Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some flaky tests #1631

Merged
merged 3 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion elasticapm/transport/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ def _process_queue(self):
# No data on buffer, but due to manual flush we should send
# an empty payload with flushed=true query param, but only
# to a local APM server (or lambda extension)
self.send("", forced_flush=True)
try:
self.send("", forced_flush=True)
self.handle_transport_success()
except Exception as e:
self.handle_transport_fail(e)
self._last_flush = timeit.default_timer()
buffer = self._init_buffer()
buffer_written = False
Expand Down
2 changes: 1 addition & 1 deletion tests/client/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def test_send_remote_failover_sync(should_try, sending_elasticapm_client, caplog
# test error
with caplog.at_level("ERROR", "elasticapm.transport"):
sending_elasticapm_client.capture_message("foo", handled=False)
sending_elasticapm_client._transport.flush()
sending_elasticapm_client._transport._flushed.wait(timeout=1)
assert sending_elasticapm_client._transport.state.did_fail()
assert_any_record_contains(caplog.records, "go away")

Expand Down
3 changes: 2 additions & 1 deletion tests/transports/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,12 @@ def test_flushed_arg(sending_elasticapm_client):
assert sending_elasticapm_client.httpserver.requests[0].args["flushed"] == "true"


@pytest.mark.flaky(reruns=3) # Trying to test automatic flushes is inherently flaky
@pytest.mark.parametrize("sending_elasticapm_client", [{"api_request_time": "100ms"}], indirect=True)
def test_flushed_arg_with_wait(sending_elasticapm_client):
sending_elasticapm_client.begin_transaction("test_type")
sending_elasticapm_client.end_transaction("test")
time.sleep(0.2)
time.sleep(0.3)
sending_elasticapm_client._transport.flush()

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