11import resource
22import typing as t
33import unittest
4+ import gc
45
56import docker
67
@@ -456,6 +457,7 @@ def testOrphanFilter(self) -> None:
456457 ctx = self ._parse_fixture ()
457458 it = ctx .filter ("//uast:RuntimeImport" )
458459 del ctx
460+ gc .collect ()
459461 # We should be able to retrieve values from the iterator
460462 # after the context has been DECREFed but the iterator
461463 # still exists
@@ -466,6 +468,7 @@ def testOrphanFilter(self) -> None:
466468 # Chaining calls has the same effect as splitting
467469 # the effect across different lines as above
468470 del it
471+ gc .collect ()
469472 it = self ._parse_fixture ().filter ("//uast:RuntimeImport" )
470473 next (it )
471474 obj = next (it ).get ()
@@ -476,6 +479,7 @@ def testOrphanIterator(self) -> None:
476479 ctx = self ._parse_fixture ()
477480 it = ctx .iterate (TreeOrder .PRE_ORDER )
478481 del ctx
482+ gc .collect ()
479483 # We should be able to retrieve values from the iterator
480484 # after the context has been DECREFed but the iterator
481485 # still exists
@@ -485,6 +489,7 @@ def testOrphanIterator(self) -> None:
485489 # Chaining calls has the same effect as splitting
486490 # the effect across different lines as above
487491 del it
492+ gc .collect ()
488493 it = self ._parse_fixture ().iterate (TreeOrder .POST_ORDER )
489494 obj = next (it )
490495 self .assertIsInstance (obj , Node )
@@ -495,16 +500,19 @@ def testLoadOrphanNode(self) -> None:
495500 # The underlying ctx should not be deallocated even if ctx goes
496501 # out of scope because the iterator is still alive
497502 del ctx
503+ gc .collect ()
498504 next (it ); next (it ); next (it );
499505 node = next (it )
500506 del it
507+ gc .collect ()
501508 # Context should not have been deallocated yet because we
502509 # want to iterate from the node onwards
503510 it2 = node .iterate (TreeOrder .PRE_ORDER )
504511 node_ext = node .node_ext
505512 # node could be deallocated here also, if we by, any chance,
506513 # we happen to be storing only the external nodes
507514 del node
515+ gc .collect ()
508516 obj = node_ext .load ()
509517 typ = obj ["@type" ]
510518 self .assertEqual ("uast:RuntimeImport" , typ )
@@ -513,6 +521,7 @@ def testFilterOrphanNode(self) -> None:
513521 ctx = self ._parse_fixture ()
514522 root = ctx .root
515523 del ctx
524+ gc .collect ()
516525 # filter should work here over the tree even if we ctx has
517526 # been DECREFed by the interpreter (it has gone out of scope)
518527 it = root .filter ("//uast:RuntimeImport" )
0 commit comments