MCPcopy Index your code
hub / github.com/python/cpython / test_len_race

Method test_len_race

Lib/test/test_weakset.py:426–448  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

424 self.assertEqual(n2, 0)
425
426 def test_len_race(self):
427 # Extended sanity checks for len() in the face of cyclic collection
428 self.addCleanup(gc.set_threshold, *gc.get_threshold())
429 for th in range(1, 100):
430 N = 20
431 gc.collect(0)
432 gc.set_threshold(th, th, th)
433 items = [RefCycle() for i in range(N)]
434 s = WeakSet(items)
435 del items
436 # All items will be collected at next garbage collection pass
437 it = iter(s)
438 try:
439 next(it)
440 except StopIteration:
441 pass
442 n1 = len(s)
443 del it
444 n2 = len(s)
445 self.assertGreaterEqual(n1, 0)
446 self.assertLessEqual(n1, N)
447 self.assertGreaterEqual(n2, 0)
448 self.assertLessEqual(n2, n1)
449
450 def test_repr(self):
451 assert repr(self.s) == repr(self.s.data)

Callers

nothing calls this directly

Calls 6

WeakSetClass · 0.90
addCleanupMethod · 0.80
assertGreaterEqualMethod · 0.80
assertLessEqualMethod · 0.80
RefCycleClass · 0.70
collectMethod · 0.45

Tested by

no test coverage detected