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

Method test_reentrancy

Lib/test/test_queue.py:1034–1060  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1032 self.assertIs(self.type2test, self.queue.SimpleQueue)
1033
1034 def test_reentrancy(self):
1035 # bpo-14976: put() may be called reentrantly in an asynchronous
1036 # callback.
1037 q = self.q
1038 gen = itertools.count()
1039 N = 10000
1040 results = []
1041
1042 # This test exploits the fact that __del__ in a reference cycle
1043 # can be called any time the GC may run.
1044
1045 class Circular(object):
1046 def __init__(self):
1047 self.circular = self
1048
1049 def __del__(self):
1050 q.put(next(gen))
1051
1052 while True:
1053 o = Circular()
1054 q.put(next(gen))
1055 del o
1056 results.append(q.get())
1057 if results[-1] >= N:
1058 break
1059
1060 self.assertEqual(results, list(range(N + 1)))
1061
1062
1063if __name__ == "__main__":

Callers

nothing calls this directly

Calls 8

CircularClass · 0.85
nextFunction · 0.85
listClass · 0.85
countMethod · 0.45
putMethod · 0.45
appendMethod · 0.45
getMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected