Пример #1
0
    def test_invalidate_wake_up_waiters(self):
        count = 3
        event = concurrent.ValidatingEvent()
        ready = concurrent.Barrier(count + 1)
        invalidated = [False] * count

        def wait(n):
            ready.wait(1)
            try:
                event.wait(1)
            except concurrent.InvalidEvent:
                invalidated[n] = True

        threads = []
        try:
            for i in range(count):
                t = concurrent.thread(wait, args=(i, ))
                t.start()
                threads.append(t)
            # Wait until all threads entered the barrier.
            ready.wait(1)
            # Give threads time to enter the event.
            time.sleep(0.5)
            event.valid = False
        finally:
            for t in threads:
                t.join()

        self.assertTrue(all(invalidated),
                        "Some threads were no invalidated: %s" % invalidated)
        self.assertFalse(event.valid, "Event is valid")
Пример #2
0
    def test_set_wake_up_waiters(self):
        count = 3
        event = concurrent.ValidatingEvent()
        ready = concurrent.Barrier(count + 1)
        woke_up = [False] * count

        def wait(n):
            ready.wait(1)
            woke_up[n] = event.wait(1)

        threads = []
        try:
            for i in range(count):
                t = concurrent.thread(wait, args=(i, ))
                t.start()
                threads.append(t)
            # Wait until all threads entered the barrier.
            ready.wait(1)
            # Give threads time to enter the event.
            time.sleep(0.5)
            event.set()
        finally:
            for t in threads:
                t.join()

        self.assertTrue(all(woke_up),
                        "Some threads did not wake up: %s" % woke_up)
        self.assertTrue(event.valid, "Event is invalid")
Пример #3
0
 def __init__(self, sdUUID, idsPath, lease, *args):
     """
     Note: lease and args are unused, needed by legacy locks.
     """
     self._lock = threading.Lock()
     self._sdUUID = sdUUID
     self._idsPath = idsPath
     self._ready = concurrent.ValidatingEvent()
Пример #4
0
 def __init__(self, sdUUID, idsPath, lease, *args, **kwargs):
     """
     Note: lease and args are unused, needed by legacy locks.
     """
     self._lock = threading.Lock()
     self._sdUUID = sdUUID
     self._idsPath = idsPath
     self._alignment = kwargs.get("alignment", sc.ALIGNMENT_1M)
     self._block_size = kwargs.get("block_size", sc.BLOCK_SIZE_512)
     self._ready = concurrent.ValidatingEvent()
Пример #5
0
 def test_wait_on_invalid_event(self):
     event = concurrent.ValidatingEvent()
     event.valid = False
     with self.assertRaises(concurrent.InvalidEvent):
         event.wait(1)
     self.assertFalse(event.valid, "Event is valid")
Пример #6
0
 def test_wait_timeout(self):
     event = concurrent.ValidatingEvent()
     self.assertFalse(event.wait(0), "Event did not timed out")
     self.assertTrue(event.valid, "Event is invalid")
Пример #7
0
 def test_wait_already_set(self):
     event = concurrent.ValidatingEvent()
     event.set()
     self.assertTrue(event.wait(1), "Timeout on set event")
     self.assertTrue(event.valid, "Event is invalid")
Пример #8
0
 def test_set(self):
     event = concurrent.ValidatingEvent()
     event.set()
     self.assertTrue(event.is_set(), "Event is not set")
     self.assertTrue(event.valid, "Event is invalid")
Пример #9
0
 def test_clear(self):
     event = concurrent.ValidatingEvent()
     event.set()
     event.clear()
     self.assertFalse(event.is_set(), "Event is set")
     self.assertTrue(event.valid, "Event is invalid")
Пример #10
0
 def test_wait_on_invalid_event(self):
     event = concurrent.ValidatingEvent()
     event.valid = False
     with pytest.raises(concurrent.InvalidEvent):
         event.wait(1)
     assert not event.valid
Пример #11
0
 def test_wait_already_set(self):
     event = concurrent.ValidatingEvent()
     event.set()
     assert event.wait(1)
     assert event.valid
Пример #12
0
 def test_wait_timeout(self):
     event = concurrent.ValidatingEvent()
     assert not event.wait(0)
     assert event.valid
Пример #13
0
 def test_clear(self):
     event = concurrent.ValidatingEvent()
     event.set()
     event.clear()
     assert not event.is_set()
     assert event.valid
Пример #14
0
 def test_create(self):
     event = concurrent.ValidatingEvent()
     assert not event.is_set()
     assert event.valid