MCPcopy Index your code
hub / github.com/RustPython/RustPython / check_len_race

Method check_len_race

Lib/test/test_weakref.py:1333–1355  ·  view source on GitHub ↗
(self, dict_type, cons)

Source from the content-addressed store, hash-verified

1331 self.check_len_cycles(weakref.WeakValueDictionary, lambda k: (1, k))
1332
1333 def check_len_race(self, dict_type, cons):
1334 # Extended sanity checks for len() in the face of cyclic collection
1335 self.addCleanup(gc.set_threshold, *gc.get_threshold())
1336 for th in range(1, 100):
1337 N = 20
1338 gc.collect(0)
1339 gc.set_threshold(th, th, th)
1340 items = [RefCycle() for i in range(N)]
1341 dct = dict_type(cons(o) for o in items)
1342 del items
1343 # All items will be collected at next garbage collection pass
1344 it = dct.items()
1345 try:
1346 next(it)
1347 except StopIteration:
1348 pass
1349 n1 = len(dct)
1350 del it
1351 n2 = len(dct)
1352 self.assertGreaterEqual(n1, 0)
1353 self.assertLessEqual(n1, N)
1354 self.assertGreaterEqual(n2, 0)
1355 self.assertLessEqual(n2, n1)
1356
1357 def test_weak_keyed_len_race(self):
1358 self.check_len_race(weakref.WeakKeyDictionary, lambda k: (k, 1))

Callers 2

Calls 10

nextFunction · 0.85
lenFunction · 0.85
addCleanupMethod · 0.80
get_thresholdMethod · 0.80
collectMethod · 0.80
set_thresholdMethod · 0.80
assertGreaterEqualMethod · 0.80
assertLessEqualMethod · 0.80
RefCycleClass · 0.70
itemsMethod · 0.45

Tested by

no test coverage detected