Harden transport test cleanup against missing _flush() invocation#2634
Draft
Copilot wants to merge 3 commits into
Draft
Harden transport test cleanup against missing _flush() invocation#2634Copilot wants to merge 3 commits into
_flush() invocation#2634Copilot wants to merge 3 commits into
Conversation
Agent-Logs-Url: https://github.com/elastic/apm-agent-python/sessions/24ccc3ac-6409-4de0-995a-7d358a38cbb2 Co-authored-by: xrmx <12932+xrmx@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix test failure in test_api_request_size_dynamic
Harden transport test cleanup against missing May 14, 2026
_flush() invocation
…quest_size_dynamic Agent-Logs-Url: https://github.com/elastic/apm-agent-python/sessions/1392e0b7-ac90-4464-82e4-3d55748c80fc Co-authored-by: xrmx <12932+xrmx@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_cleanup_flush_mock_bufferstransport._flushed.wait(timeout=0.1)withtransport.flush()intest_api_request_size_dynamicOriginal prompt
A GitHub Actions test job is failing in repository
elastic/apm-agent-python.Failing job:
2583920907875920681064.github/workflows/test.ymlcd221144bded49f871e16e96b11f5c9d5e0553ebObserved failure from logs:
tests/transports/test_base.py::test_api_request_size_dynamicTypeError: cannot unpack non-iterable NoneType object_cleanup_flush_mock_buffers(mock_flush)is called andmock_flush.call_argsisNone.Relevant code context:
tests/transports/test_base.py, helper_cleanup_flush_mock_buffers()unconditionally unpacksmock_flush.call_args.test_api_request_size_dynamic, the test waits for onlytransport._flushed.wait(timeout=0.1)after queueing an event, which is racy on Windows because transport flushing is asynchronous._flush()had not yet been called when the helper ran.Requested change:
Implementation guidance:
_cleanup_flush_mock_buffers(mock_flush)toleratemock_flush.call_args is Noneand return early instead of unpacking.Acceptance criteria:
TypeErrorwhen_flush()has not yet been invoked.elastic/apm-agent-python.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.
Assistant: The failure is in the Windows job defined at
.github/workflows/test.yml, specifically the Python 3.8 / frameworknone/asyncio=truematrix entry. The failing test istests/transports/test_base.py::test_api_request_size_dynamic.Root cause
The test assumes
_flush()has already been called after:0.1sontransport._flushedBut the transport thread flush timing is intentionally asynchronous and queue wakeup depends on
ChilledQueuetiming and thread scheduling inelasticapm/transport/base.py. On Windows, that makes this race visible.The immediate exception comes from
_cleanup_flush_mock_buffers:If
_flush()has not been called yet,mock_flush.call_argsisNone, so unpacking fails with:TypeError: cannot unpack non-iterable NoneType objectBest fix
Make the test deterministic by forcing a flush instead of waiting for a background flush to maybe happen.
Suggested change
Update
test_api_request_size_dynamiclike this:Why this works
Transport.flush()in [`elasticapm/transport...This pull request was created from Copilot chat.