@@ -188,14 +188,15 @@ def test_export_event(self, telemetry_client_setup):
188
188
client = telemetry_client_setup ["client" ]
189
189
client ._flush = MagicMock ()
190
190
191
- for i in range (TelemetryClient .DEFAULT_BATCH_SIZE - 1 ):
191
+ batch_size = client ._batch_size
192
+
193
+ for i in range (batch_size - 1 ):
192
194
client ._export_event (f"event-{ i } " )
193
195
194
196
client ._flush .assert_not_called ()
195
- assert len (client ._events_batch ) == TelemetryClient .DEFAULT_BATCH_SIZE - 1
196
-
197
- # Add one more event to reach batch size (this will trigger flush)
198
- client ._export_event (f"event-{ TelemetryClient .DEFAULT_BATCH_SIZE - 1 } " )
197
+ assert len (client ._events_batch ) == batch_size - 1
198
+
199
+ client ._export_event (f"event-{ batch_size - 1 } " )
199
200
200
201
client ._flush .assert_called_once ()
201
202
@@ -658,11 +659,9 @@ def test_telemetry_client_concurrent_flush_operations(self, race_condition_setup
658
659
executor = executor ,
659
660
)
660
661
661
- # Mock _send_telemetry to avoid actual network calls
662
662
client ._send_telemetry = MagicMock ()
663
663
664
- # Add events to trigger flush
665
- for i in range (TelemetryClient .DEFAULT_BATCH_SIZE - 1 ):
664
+ for i in range (client ._batch_size - 1 ):
666
665
client ._export_event (f"event-{ i } " )
667
666
668
667
# Track flush operations
@@ -690,13 +689,13 @@ def concurrent_flush():
690
689
# Verify flush was called the expected number of times
691
690
assert flush_count == 10
692
691
693
- # Verify _send_telemetry was called at least once (some calls may have empty batches due to lock)
694
- assert client ._send_telemetry .call_count > = 1
692
+ # Verify _send_telemetry was called once
693
+ assert client ._send_telemetry .call_count = = 1
695
694
696
695
# Verify that the total events processed is correct (no data loss)
697
696
# The first flush should have processed all events, subsequent flushes should have empty batches
698
697
total_events_sent = sum (len (call .args [0 ]) for call in client ._send_telemetry .call_args_list )
699
- assert total_events_sent == TelemetryClient . DEFAULT_BATCH_SIZE - 1
698
+ assert total_events_sent == client . _batch_size - 1
700
699
701
700
def test_telemetry_client_factory_concurrent_initialization (self , race_condition_setup ):
702
701
"""Test race conditions in TelemetryClientFactory.initialize_telemetry_client with concurrent access."""
0 commit comments