Test set contains operation combined with mutation.
(self)
| 35 | |
| 36 | class 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) |