Skip to content

e2e: automate pre-teardown leak checks - #1262

Merged
Carter Tinney (cartertinney) merged 6 commits into
mainfrom
agents/fix-memory-leaks-and-reenable-checks
Sep 3, 2026
Merged

e2e: automate pre-teardown leak checks#1262
Carter Tinney (cartertinney) merged 6 commits into
mainfrom
agents/fix-memory-leaks-and-reenable-checks

Conversation

@cartertinney

@cartertinney Carter Tinney (cartertinney) commented Sep 2, 2026

Copy link
Copy Markdown
Member

Summary

  • move opted-in inner leak tracking into pytest's call phase
  • re-enable leak checks that were disabled by test-local reference false positives
  • remove repeated per-test snapshot/check calls and leak-specific variable cleanup
  • retain primitive assertion data in method/C2D callbacks instead of SDK objects

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

  • production MQTT code and related unit tests exactly match the pre-fix branch state
  • all 38 affected IoT Hub E2E tests collect successfully
  • Ruff and Black pass for the retained E2E changes
  • the eight known cancellation-leak tests are explicitly opted out pending the refactor

Live IoT Hub E2E execution is delegated to CI.

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>
@cartertinney Carter Tinney (cartertinney) changed the title e2e: automate pre-teardown leak checks e2e: fix disabled leak checks + automate pre-teardown leak checks Sep 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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>
@cartertinney Carter Tinney (cartertinney) changed the title e2e: fix disabled leak checks + automate pre-teardown leak checks fix: release MQTT leaks and automate e2e checks Sep 2, 2026
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>
@cartertinney Carter Tinney (cartertinney) changed the title fix: release MQTT leaks and automate e2e checks e2e: automate pre-teardown leak checks Sep 3, 2026
@cartertinney Carter Tinney (cartertinney) changed the title e2e: automate pre-teardown leak checks fix: release MQTT leaks and automate e2e checks Sep 3, 2026
@cartertinney Carter Tinney (cartertinney) changed the title fix: release MQTT leaks and automate e2e checks e2e: automate pre-teardown leak checks Sep 3, 2026
@cartertinney
Carter Tinney (cartertinney) merged commit 6aa8144 into main Sep 3, 2026
41 checks passed
@cartertinney
Carter Tinney (cartertinney) deleted the agents/fix-memory-leaks-and-reenable-checks branch September 3, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants