test(ingestor_manager): force gc.collect() after each test to avoid __del__ flake
IngestorManager.__del__ calls asyncio.run(self.shutdown()). Adding tests/unit/connection/test_pool.py shifted GC timing enough that a cyclic-referenced IngestorManager instance from an earlier test was swept mid test___del__, double-calling the patched asyncio mock and failing the assertion. Deterministic gc.collect() after each test in this file keeps finalizers scoped to their own test.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import gc
|
||||||
from unittest.mock import AsyncMock, MagicMock, call, patch
|
from unittest.mock import AsyncMock, MagicMock, call, patch
|
||||||
|
|
||||||
from pytest import fixture, mark
|
from pytest import fixture, mark
|
||||||
@@ -15,6 +16,18 @@ metadata = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@fixture(autouse=True)
|
||||||
|
def _collect_garbage_after_test():
|
||||||
|
# ponytail: IngestorManager.__del__ calls asyncio.run(self.shutdown()); if a
|
||||||
|
# cyclic-referenced instance from a previous test is swept mid-test by the
|
||||||
|
# generational GC, it can double-call whatever asyncio mock happens to be
|
||||||
|
# patched at that moment (e.g. test___del__). Force a deterministic sweep
|
||||||
|
# after each test so finalizers run in their own test's scope. Upgrade path:
|
||||||
|
# only needed if IngestorManager stops relying on __del__ for cleanup.
|
||||||
|
yield
|
||||||
|
gc.collect()
|
||||||
|
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
@patch('ingestor.managers.ingestor_manager.DataManager')
|
@patch('ingestor.managers.ingestor_manager.DataManager')
|
||||||
@patch('ingestor.managers.ingestor_manager.ResourceManager')
|
@patch('ingestor.managers.ingestor_manager.ResourceManager')
|
||||||
|
|||||||
Reference in New Issue
Block a user