def test_waitforthreads_restore(self): """Waitforthreads get_ident is restored to original one.""" if hasattr(threading, 'get_ident'): expected = threading.get_ident else: expected = threading._get_ident thread = launch_thread(None, thread_function, 0) time.sleep(0.01) waitforthreads([thread]) if hasattr(threading, 'get_ident'): self.assertEqual(threading.get_ident, expected) else: self.assertEqual(threading._get_ident, expected)
def test_waitforthreads_restore(self): """Waitforthreads get_ident is restored to original one.""" if hasattr(threading, 'get_ident'): expected = threading.get_ident else: expected = threading._get_ident thread = thread_function(0) time.sleep(0.01) waitforthreads([thread]) if hasattr(threading, 'get_ident'): self.assertEqual(threading.get_ident, expected) else: self.assertEqual(threading._get_ident, expected)
def test_waitforthreads_multiple(self): """Waitforthreads waits for multiple threads.""" threads = [] for _ in range(5): threads.append(launch_thread(thread_function, 0.01)) time.sleep(0.1) self.assertEqual(list(waitforthreads(threads)), threads)
def test_waitforthreads_multiple(self): """Waitforthreads waits for multiple threads.""" threads = [] for _ in range(5): threads.append(thread_function(0.01)) time.sleep(0.1) self.assertEqual(waitforthreads(threads), threads)
def test_waitforthreads_spurious(self): """Waitforthreads tolerates spurious wakeups.""" lock = threading.RLock() thread = launch_thread(spurious_wakeup_function, 0.1, lock) self.assertEqual(list(waitforthreads([thread])), [thread])
def test_waitforthreads_timeout(self): """Waitforthreads returns empty list if timeout.""" thread = launch_thread(thread_function, 0.1) self.assertEqual(list(waitforthreads([thread], timeout=0.01)), [])
def test_waitforthreads_single(self): """Waitforthreads waits for a single thread.""" thread = launch_thread(thread_function, 0.01) self.assertEqual(list(waitforthreads([thread]))[0], thread)
def test_waitforthreads_timeout(self): """Waitforthreads returns empty list if timeout.""" thread = thread_function(0.1) self.assertEqual(waitforthreads([thread], timeout=0.01), [])
def test_waitforthreads_single(self): """Waitforthreads waits for a single thread.""" thread = thread_function(0.01) self.assertEqual(waitforthreads([thread])[0], thread)
def test_waitforthreads_spurious(self): """Waitforthreads tolerates spurious wakeups.""" lock = threading.RLock() thread = spurious_wakeup_function(0.1, lock) self.assertEqual(list(waitforthreads([thread])), [thread])
def test_waitforthreads_single(self): """Waitforthreads waits for a single thread.""" thread = launch_thread(thread_function, 0.01) self.assertEqual(list(waitforthreads([thread]))[0], thread)