Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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])
Example #6
0
 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)), [])
Example #7
0
 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)
Example #8
0
 def test_waitforthreads_timeout(self):
     """Waitforthreads returns empty list if timeout."""
     thread = thread_function(0.1)
     self.assertEqual(waitforthreads([thread], timeout=0.01), [])
Example #9
0
 def test_waitforthreads_single(self):
     """Waitforthreads waits for a single thread."""
     thread = thread_function(0.01)
     self.assertEqual(waitforthreads([thread])[0], thread)
Example #10
0
 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])
Example #11
0
 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)