(self, dict_type, cons)
| 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)) |
no test coverage detected