e2e: automate pre-teardown leak checks - #1262
Merged
Carter Tinney (cartertinney) merged 6 commits intoSep 3, 2026
Merged
Conversation
Run opted-in leak tracking around pytest's call phase so test-local references are released before checking while the client is still alive. Remove the repeated lifecycle calls and leak-specific variable cleanup from individual tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Carter Tinney (cartertinney)
September 2, 2026 22:38
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The centralized hook correctly preserves opt-in behavior and teardown ordering without identified regressions.
Pull request overview
Moves opted-in leak detection into pytest’s call phase so checks run after test frames are released but before client teardown.
Changes:
- Automates baseline capture and leak checking through
pytest_runtest_call. - Re-enables previously disabled leak checks and removes manual tracking calls.
- Retains primitive callback data instead of tracked SDK objects.
File summaries
| File | Description |
|---|---|
tests/e2e/iothub_e2e/conftest.py |
Adds automated pre-teardown leak checks. |
tests/e2e/iothub_e2e/sync/test_sync_twin.py |
Removes manual twin leak tracking. |
tests/e2e/iothub_e2e/sync/test_sync_send_message.py |
Removes manual messaging leak tracking. |
tests/e2e/iothub_e2e/sync/test_sync_sas_renewal.py |
Automates SAS renewal leak checking. |
tests/e2e/iothub_e2e/sync/test_sync_methods.py |
Retains method request assertion data only. |
tests/e2e/iothub_e2e/sync/test_sync_connect_disconnect.py |
Removes manual connection leak checks. |
tests/e2e/iothub_e2e/sync/test_sync_c2d.py |
Retains decoded C2D data only. |
tests/e2e/iothub_e2e/aio/test_twin.py |
Removes manual async twin leak tracking. |
tests/e2e/iothub_e2e/aio/test_twin_stress.py |
Automates twin stress leak checking. |
tests/e2e/iothub_e2e/aio/test_send_message.py |
Removes manual async messaging leak tracking. |
tests/e2e/iothub_e2e/aio/test_send_message_stress.py |
Automates messaging stress leak checking. |
tests/e2e/iothub_e2e/aio/test_sas_renewal.py |
Removes manual SAS renewal cleanup. |
tests/e2e/iothub_e2e/aio/test_methods.py |
Retains method request assertion data only. |
tests/e2e/iothub_e2e/aio/test_connect_disconnect.py |
Removes manual connection leak checks. |
tests/e2e/iothub_e2e/aio/test_connect_disconnect_stress.py |
Automates connection stress leak checking. |
tests/e2e/iothub_e2e/aio/test_c2d.py |
Retains decoded C2D data only. |
Review details
- Files reviewed: 16/16 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Remove transport callbacks when operations complete through timeout or retry paths, and discard Paho QoS state when the SDK cancels in-flight work. This prevents cancelled publish and subscribe objects from surviving dropped-connection tests or being completed again by late acknowledgements. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove the MQTT cancellation changes while that module is being refactored. Keep the automatic leak-check infrastructure, but leave the eight tests that expose the known cancellation leaks opted out until the refactor lands. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit 2bb3263.
This reverts commit 364a6ca.
Avishek (avishekpant)
approved these changes
Sep 3, 2026
Carter Tinney (cartertinney)
deleted the
agents/fix-memory-leaks-and-reenable-checks
branch
September 3, 2026 15:54
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.
Summary
Why
Running the inner check inside the test body kept expected-exception tracebacks and completed failed tasks/futures alive, producing false positives. The hook now captures its baseline after fixture setup and checks after the test frame is released, but before client shutdown can hide genuine leaks.
The reliable checks exposed genuine MQTT cancellation leaks in eight dropped-connection tests. Those tests remain opted out with explicit TODOs while the MQTT module is being refactored; the diagnosis is preserved for reevaluation after that work lands.
Validation
Live IoT Hub E2E execution is delegated to CI.