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
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
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])
def worker(): ready.append(gruvi.current_fiber()) try: gruvi.sleep(0.1) except Exception as e: exceptions.append(e)
def run_test(): with cond: ready.append(gruvi.current_fiber()) timeout = random.choice((None, 0.1)) result.append(cond.wait(timeout=timeout))