コード例 #1
0
ファイル: test_sync.py プロジェクト: Ed-von-Schleck/gruvi
 def lock_unlock(self, lock, count):
     failed = 0
     timeouts = 0
     for i in range(count):
         gruvi.sleep(random.randint(0, 14)/10000)
         timeout = random.choice((None, None, None, 0.001))
         while not lock.acquire(timeout=timeout):
             timeouts += 1
         gruvi.sleep(random.randint(0, 14)/10000)
         if lock._locked != 1 or lock._owner is not gruvi.current_fiber():
             failed += 1
         lock.acquire()
         gruvi.sleep(random.randint(0, 14)/10000)
         if lock._locked != 2 or lock._owner is not gruvi.current_fiber():
             failed += 1
         lock.release()
         gruvi.sleep(random.randint(0, 14)/10000)
         if lock._locked != 1 or lock._owner is not gruvi.current_fiber():
             failed += 1
         lock.release()
     return failed
コード例 #2
0
 def lock_unlock(self, lock, count):
     failed = 0
     timeouts = 0
     for i in range(count):
         gruvi.sleep(random.randint(0, 2) / 1000)
         timeout = random.choice((None, 0.001))
         while not lock.acquire(timeout=timeout):
             timeouts += 1
         gruvi.sleep(random.randint(0, 2) / 1000)
         if lock._locked != 1 or lock._owner is not gruvi.current_fiber():
             failed += 1
         lock.acquire()
         gruvi.sleep(random.randint(0, 2) / 1000)
         if lock._locked != 2 or lock._owner is not gruvi.current_fiber():
             failed += 1
         lock.release()
         gruvi.sleep(random.randint(0, 2) / 1000)
         if lock._locked != 1 or lock._owner is not gruvi.current_fiber():
             failed += 1
         lock.release()
     return failed
コード例 #3
0
ファイル: test_logging.py プロジェクト: Ed-von-Schleck/gruvi
 def test_fiber_context(self):
     # Ensure that both a logging context and a fiber context are added.
     self.logger.setLevel(logging.DEBUG)
     gruvi.current_fiber().context = 'fibctx'
     logger = get_logger('logctx', name='gruvi_test')
     logger.debug('foo bar')
     messages = self.get_messages()
     self.assertEqual(len(messages), 1)
     self.assertIn('fibctx', messages[0])
     self.assertIn('logctx', messages[0])
     self.assertIn('foo bar', messages[0])
     logger = get_logger(name='gruvi_test')
     logger.debug('foo bar')
     messages = self.get_messages()
     self.assertEqual(len(messages), 1)
     self.assertIn('fibctx', messages[0])
     self.assertNotIn('logctx', messages[0])
     self.assertIn('foo bar', messages[0])
コード例 #4
0
ファイル: test_fibers.py プロジェクト: Ed-von-Schleck/gruvi
 def worker():
     ready.append(gruvi.current_fiber())
     try:
         gruvi.sleep(0.1)
     except Exception as e:
         exceptions.append(e)
コード例 #5
0
ファイル: test_sync.py プロジェクト: Ed-von-Schleck/gruvi
 def run_test():
     with cond:
         ready.append(gruvi.current_fiber())
         timeout = random.choice((None, 0.1))
         result.append(cond.wait(timeout=timeout))
コード例 #6
0
 def run_test():
     with cond:
         ready.append(gruvi.current_fiber())
         timeout = random.choice((None, 0.1))
         result.append(cond.wait(timeout=timeout))
コード例 #7
0
ファイル: test_fibers.py プロジェクト: geertj/gruvi
 def worker():
     ready.append(gruvi.current_fiber())
     try:
         gruvi.sleep(0.1)
     except Exception as e:
         exceptions.append(e)