def test_timeout(self): # Ensure that the timeout argument to acquire() works. hub = get_hub() lock = gruvi.RLock() sync = gruvi.Lock() def lock_rlock(): lock.acquire() sync.acquire() lock.release() # This needs a new fiber, as the same fiber *can* lock the same RLock twice. sync.acquire() fiber = gruvi.spawn(lock_rlock) gruvi.sleep(0) self.assertTrue(lock.locked()) t0 = hub.loop.now() self.assertFalse(lock.acquire(timeout=0.01)) t1 = hub.loop.now() # Internally the event loop uses timestamps with a 1ms granularity. So # allow for that. self.assertGreaterEqual(t1 - t0, 10) sync.release() fiber.join() self.assertFalse(lock._callbacks)
def test_get_timeout(self): # Ensure the "timeout" argument to Queue.get() works queue = gruvi.Queue() hub = get_hub() t0 = hub.loop.now() self.assertRaises(gruvi.QueueEmpty, queue.get, timeout=0.01) t1 = hub.loop.now() self.assertGreaterEqual(t1-t0, 10)
def test_get_timeout(self): # Ensure the "timeout" argument to Queue.get() works queue = gruvi.Queue() hub = get_hub() t0 = hub.loop.now() self.assertRaises(gruvi.QueueEmpty, queue.get, timeout=0.01) t1 = hub.loop.now() self.assertGreaterEqual(t1 - t0, 10)
def test_put_timeout(self): # Ensure the "timeout" argument to Queue.put() works queue = gruvi.Queue(maxsize=10) queue.put('foo', size=10) hub = get_hub() t0 = hub.loop.now() self.assertRaises(gruvi.QueueFull, queue.put, 'bar', timeout=0.01) t1 = hub.loop.now() self.assertGreaterEqual(t1-t0, 10)
def test_put_timeout(self): # Ensure the "timeout" argument to Queue.put() works queue = gruvi.Queue(maxsize=10) queue.put('foo', size=10) hub = get_hub() t0 = hub.loop.now() self.assertRaises(gruvi.QueueFull, queue.put, 'bar', timeout=0.01) t1 = hub.loop.now() self.assertGreaterEqual(t1 - t0, 10)
def test_timeout(self): # Ensure that the timeout argument to acquire() works. hub = get_hub() lock = gruvi.Lock() lock.acquire() t0 = hub.loop.now() self.assertFalse(lock.acquire(timeout=0.01)) t1 = hub.loop.now() self.assertGreater(t1-t0, 10) self.assertFalse(lock._callbacks)
def test_timeout(self): # Ensure that the timeout argument to acquire() works. hub = get_hub() lock = gruvi.Lock() lock.acquire() t0 = hub.loop.now() self.assertFalse(lock.acquire(timeout=0.01)) t1 = hub.loop.now() self.assertGreater(t1 - t0, 10) self.assertFalse(lock._callbacks)
def test_inherit_handle(self): # Ensure that it's possible to pass a handle to the child. # Note: The "ipc" flag doubles as a read/write flag. hub = get_hub() handle = pyuv.Pipe(hub.loop, True) proc = Process() proc.spawn(python_script(['catn', '3']), extra_handles=[handle]) stream = StreamClient() stream.connect(handle) stream.write(b'Foo\n') self.assertEqual(stream.readline(), b'Foo\n') stream.write_eof() self.assertEqual(stream.readline(), b'') stream.close() proc.wait() self.assertEqual(proc.returncode, 0) proc.close()
def test_pass_ssl_handle_over_ssl(self): server = IpcServer(self.ssl_s_args['ssl']) pipe = self.pipename() server.listen(pipe, ipc=True, **self.ssl_s_args) client = IpcClient() client.connect(pipe, ipc=True, **self.ssl_cp_args) self.assertEqual(client.call('type'), 'pipe') s1, s2 = socketpair() h2 = pyuv.Pipe(get_hub().loop) h2.open(s2.fileno()) client.call('ssl_handle', h2) c1 = IpcClient() c1.connect(s1.fileno(), **self.ssl_cp_args) self.assertEqual(c1.call('ping'), 'pong') self.assertEqual(c1.call('type'), 'tcp') s1.close(); s2.close() c1.close(); h2.close() client.close(); server.close()
def test_timeout(self): # Ensure that the timeout argument to acquire() works. hub = get_hub() lock = gruvi.RLock() sync = gruvi.Lock() def lock_rlock(): lock.acquire() sync.acquire() lock.release() # This needs a new fiber, as the same fiber *can* lock the same RLock twice. sync.acquire() fiber = gruvi.spawn(lock_rlock) gruvi.sleep(0) self.assertTrue(lock.locked()) t0 = hub.loop.now() self.assertFalse(lock.acquire(timeout=0.01)) t1 = hub.loop.now() # Internally the event loop uses timestamps with a 1ms granularity. So # allow for that. self.assertGreaterEqual(t1-t0, 10) sync.release() fiber.join() self.assertFalse(lock._callbacks)