(self, dict_type, cons)
| 1349 | self.check_len_cycles(weakref.WeakValueDictionary, lambda k: (1, k)) |
| 1350 | |
| 1351 | def check_len_race(self, dict_type, cons): |
| 1352 | # Extended sanity checks for len() in the face of cyclic collection |
| 1353 | self.addCleanup(gc.set_threshold, *gc.get_threshold()) |
| 1354 | for th in range(1, 100): |
| 1355 | N = 20 |
| 1356 | gc.collect(0) |
| 1357 | gc.set_threshold(th, th, th) |
| 1358 | items = [RefCycle() for i in range(N)] |
| 1359 | dct = dict_type(cons(o) for o in items) |
| 1360 | del items |
| 1361 | # All items will be collected at next garbage collection pass |
| 1362 | it = dct.items() |
| 1363 | try: |
| 1364 | next(it) |
| 1365 | except StopIteration: |
| 1366 | pass |
| 1367 | n1 = len(dct) |
| 1368 | del it |
| 1369 | n2 = len(dct) |
| 1370 | self.assertGreaterEqual(n1, 0) |
| 1371 | self.assertLessEqual(n1, N) |
| 1372 | self.assertGreaterEqual(n2, 0) |
| 1373 | self.assertLessEqual(n2, n1) |
| 1374 | |
| 1375 | def test_weak_keyed_len_race(self): |
| 1376 | self.check_len_race(weakref.WeakKeyDictionary, lambda k: (k, 1)) |
no test coverage detected