Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 0cdc3d0

Browse files
ncordondennwc
authored andcommitted
Adds triggering of GC in tests when doing the deletions
Signed-off-by: ncordon <nacho.cordon.castillo@gmail.com>
1 parent 43643ff commit 0cdc3d0

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

bblfsh/test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import resource
22
import typing as t
33
import unittest
4+
import gc
45

56
import 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

Comments
 (0)