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

Method test_contains_mutate

Lib/test/test_free_threading/test_set.py:37–68  ·  view source on GitHub ↗

Test set contains operation combined with mutation.

(self)

Source from the content-addressed store, hash-verified

35
36class RaceTestBase:
37 def test_contains_mutate(self):
38 """Test set contains operation combined with mutation."""
39 barrier = Barrier(2, timeout=2)
40 s = set()
41 done = Event()
42
43 NUM_LOOPS = 1000
44
45 def read_set():
46 barrier.wait()
47 while not done.is_set():
48 for i in range(self.SET_SIZE):
49 item = i >> 1
50 result = item in s
51
52 def mutate_set():
53 barrier.wait()
54 for i in range(NUM_LOOPS):
55 s.clear()
56 for j in range(self.SET_SIZE):
57 s.add(j)
58 for j in range(self.SET_SIZE):
59 s.discard(j)
60 # executes the set_swap_bodies() function
61 s.__iand__(set(k for k in range(10, 20)))
62 done.set()
63
64 threads = [Thread(target=read_set), Thread(target=mutate_set)]
65 for t in threads:
66 t.start()
67 for t in threads:
68 t.join()
69
70 def test_contains_frozenset(self):
71 barrier = Barrier(3, timeout=2)

Callers

nothing calls this directly

Calls 6

BarrierClass · 0.90
EventClass · 0.90
ThreadClass · 0.90
setFunction · 0.85
startMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected