Skip to content

tests: enable transports tests poking with request_size for Python 3.12+ #2261

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

Merged
merged 1 commit into from
Apr 7, 2025
Merged
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
26 changes: 13 additions & 13 deletions tests/transports/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,43 +157,43 @@ def test_api_request_time_dynamic(mock_send, caplog, elasticapm_client):
assert mock_send.call_count == 0


@pytest.mark.skipif(sys.version_info >= (3, 12), reason="Failing locally on 3.12.0rc1") # TODO py3.12
def _cleanup_flush_mock_buffers(mock_flush):
args, kwargs = mock_flush.call_args
buffer = args[0]
buffer.close()


@mock.patch("elasticapm.transport.base.Transport._flush")
def test_api_request_size_dynamic(mock_flush, caplog, elasticapm_client):
elasticapm_client.config.update(version="1", api_request_size="100b")
elasticapm_client.config.update(version="1", api_request_size="9b")
transport = Transport(client=elasticapm_client, queue_chill_count=1)
transport.start_thread()
try:
with caplog.at_level("DEBUG", "elasticapm.transport"):
# we need to add lots of uncompressible data to fill up the gzip-internal buffer
for i in range(12):
transport.queue("error", "".join(random.choice(string.ascii_letters) for i in range(2000)))
transport.queue("error", "".join(random.choice(string.ascii_letters) for i in range(2000)))
transport._flushed.wait(timeout=0.1)
_cleanup_flush_mock_buffers(mock_flush)
assert mock_flush.call_count == 1
elasticapm_client.config.update(version="1", api_request_size="1mb")
with caplog.at_level("DEBUG", "elasticapm.transport"):
# we need to add lots of uncompressible data to fill up the gzip-internal buffer
for i in range(12):
transport.queue("error", "".join(random.choice(string.ascii_letters) for i in range(2000)))
transport.queue("error", "".join(random.choice(string.ascii_letters) for i in range(2000)))
transport._flushed.wait(timeout=0.1)
# Should be unchanged because our buffer limit is much higher.
assert mock_flush.call_count == 1
finally:
transport.close()


@pytest.mark.skipif(sys.version_info >= (3, 12), reason="Failing locally on 3.12.0rc1") # TODO py3.12
@mock.patch("elasticapm.transport.base.Transport._flush")
@pytest.mark.parametrize("elasticapm_client", [{"api_request_size": "100b"}], indirect=True)
@pytest.mark.parametrize("elasticapm_client", [{"api_request_size": "9b"}], indirect=True)
def test_flush_time_size(mock_flush, caplog, elasticapm_client):
transport = Transport(client=elasticapm_client, queue_chill_count=1)
transport.start_thread()
try:
with caplog.at_level("DEBUG", "elasticapm.transport"):
# we need to add lots of uncompressible data to fill up the gzip-internal buffer
for i in range(12):
transport.queue("error", "".join(random.choice(string.ascii_letters) for i in range(2000)))
transport.queue("error", "".join(random.choice(string.ascii_letters) for i in range(2000)))
transport._flushed.wait(timeout=0.1)
_cleanup_flush_mock_buffers(mock_flush)
assert mock_flush.call_count == 1
finally:
transport.close()
Expand Down
Loading