Skip to content

Commit f76eb23

Browse files
author
Colton Myers
authored
Fix some flaky tests (#1631)
* Make test_flushed_arg_with_wait less flaky * Fix flaky test_send_remote_failover_sync * Fix the actual race condition and a small bug with forced flushes
1 parent ef9fb4b commit f76eb23

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

elasticapm/transport/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ def _process_queue(self):
180180
# No data on buffer, but due to manual flush we should send
181181
# an empty payload with flushed=true query param, but only
182182
# to a local APM server (or lambda extension)
183-
self.send("", forced_flush=True)
183+
try:
184+
self.send("", forced_flush=True)
185+
self.handle_transport_success()
186+
except Exception as e:
187+
self.handle_transport_fail(e)
184188
self._last_flush = timeit.default_timer()
185189
buffer = self._init_buffer()
186190
buffer_written = False

tests/client/client_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def test_send_remote_failover_sync(should_try, sending_elasticapm_client, caplog
246246
# test error
247247
with caplog.at_level("ERROR", "elasticapm.transport"):
248248
sending_elasticapm_client.capture_message("foo", handled=False)
249-
sending_elasticapm_client._transport.flush()
249+
sending_elasticapm_client._transport._flushed.wait(timeout=1)
250250
assert sending_elasticapm_client._transport.state.did_fail()
251251
assert_any_record_contains(caplog.records, "go away")
252252

tests/transports/test_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,12 @@ def test_flushed_arg(sending_elasticapm_client):
266266
assert sending_elasticapm_client.httpserver.requests[0].args["flushed"] == "true"
267267

268268

269+
@pytest.mark.flaky(reruns=3) # Trying to test automatic flushes is inherently flaky
269270
@pytest.mark.parametrize("sending_elasticapm_client", [{"api_request_time": "100ms"}], indirect=True)
270271
def test_flushed_arg_with_wait(sending_elasticapm_client):
271272
sending_elasticapm_client.begin_transaction("test_type")
272273
sending_elasticapm_client.end_transaction("test")
273-
time.sleep(0.2)
274+
time.sleep(0.3)
274275
sending_elasticapm_client._transport.flush()
275276

276277
assert sending_elasticapm_client.httpserver.requests[1].args["flushed"] == "true"

0 commit comments

Comments
 (0)