def test_await_multi(): q1 = Queue('first') q2 = Queue('second') blocked = False def in_thread(): nonlocal blocked blocked = True q = Queue.await_multi([q1, q2], 1) blocked = False return q with futures.ThreadPoolExecutor(max_workers=5) as executor: future = executor.submit(in_thread) time.sleep(0.005) assert blocked q1.push(TaskFactory()) time.sleep(0.005) assert not blocked assert future.result().name == q1.name future = executor.submit(in_thread) time.sleep(0.005) q2.push(TaskFactory()) q1.push(TaskFactory()) assert future.result().name == q2.name assert Queue.await_multi([q1, q2], 1).name == q1.name
def test_queue_await_multi_empty(): assert Queue.await_multi([Queue()], 1) is None
def in_thread(): nonlocal blocked blocked = True q = Queue.await_multi([q1, q2], 1) blocked = False return q