def test_connection_pool(self): '''Test the connection pool. A very important test!''' client = Echo(self.server_cfg.addresses[0], pool_size=2) self.assertEqual(client._loop, get_event_loop()) # self.assertEqual(client.pool.pool_size, 2) self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 0) self.assertEqual(client.sessions, 0) self.assertEqual(client._requests_processed, 0) # response = yield from client(b'test connection') self.assertEqual(response, b'test connection') self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 1) self.assertEqual(client.sessions, 1) self.assertEqual(client._requests_processed, 1) # response = yield from client(b'test connection 2') self.assertEqual(response, b'test connection 2') self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 1) self.assertEqual(client.sessions, 1) self.assertEqual(client._requests_processed, 2) # result = yield from gather(client(b'ciao'), client(b'pippo'), client(b'foo')) self.assertEqual(len(result), 3) self.assertTrue(b'ciao' in result) self.assertTrue(b'pippo' in result) self.assertTrue(b'foo' in result) self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 2) self.assertEqual(client.sessions, 2) self.assertEqual(client._requests_processed, 5) # # drop a connection yield from run_in_loop(client._loop, self._drop_conection, client) # result = yield from gather(client(b'ciao'), client(b'pippo'), client(b'foo')) self.assertEqual(len(result), 3) self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 2) self.assertEqual(client.sessions, 3) self.assertEqual(client._requests_processed, 8) # yield from run_in_loop(client._loop, client.pool.close) # self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 0) self.assertEqual(client.sessions, 3) self.assertEqual(client._requests_processed, 8)
def test_connection_pool(self): """Test the connection pool. A very important test!""" client = Echo(self.server_cfg.addresses[0], pool_size=2) self.assertNotEqual(client._loop, get_event_loop()) # self.assertEqual(client.pool.pool_size, 2) self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 0) self.assertEqual(client.sessions, 0) self.assertEqual(client._requests_processed, 0) # response = yield client(b"test connection") self.assertEqual(response, b"test connection") self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 1) self.assertEqual(client.sessions, 1) self.assertEqual(client._requests_processed, 1) # response = yield client(b"test connection 2") self.assertEqual(response, b"test connection 2") self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 1) self.assertEqual(client.sessions, 1) self.assertEqual(client._requests_processed, 2) # result = yield multi_async((client(b"ciao"), client(b"pippo"), client(b"foo"))) self.assertEqual(len(result), 3) self.assertTrue(b"ciao" in result) self.assertTrue(b"pippo" in result) self.assertTrue(b"foo" in result) self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 2) self.assertEqual(client.sessions, 2) self.assertEqual(client._requests_processed, 5) # # drop a connection yield run_in_loop(client._loop, self._drop_conection, client) # result = yield multi_async((client(b"ciao"), client(b"pippo"), client(b"foo"))) self.assertEqual(len(result), 3) self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 2) self.assertEqual(client.sessions, 3) self.assertEqual(client._requests_processed, 8) # yield run_in_loop(client._loop, client.pool.close) # self.assertEqual(client.pool.in_use, 0) self.assertEqual(client.pool.available, 0) self.assertEqual(client.sessions, 3) self.assertEqual(client._requests_processed, 8)
def test_run_in_thread_loop(self): event_loop = get_event_loop() def simple(a, b): return a + b d = run_in_loop(event_loop, simple, 1, 2) self.assertIsInstance(d, Future) result = yield d self.assertEqual(result, 3) d = run_in_loop(event_loop, simple, 1, 'a') self.assertIsInstance(d, Future) try: result = yield d except TypeError: pass else: assert False, "TypeError not raised"
def test_run_in_io_loop(self): event_loop = pulsar.get_io_loop() def simple(a, b): return a + b d = run_in_loop(event_loop, simple, 1, 2) self.assertIsInstance(d, Future) self.assertEqual(d._loop, event_loop) result = yield d self.assertEqual(result, 3) yield self. async .assertRaises(TypeError, run_in_loop, event_loop, simple, 1, 'a')
def test_run_in_io_loop(self): event_loop = pulsar.get_io_loop() def simple(a, b): return a + b d = run_in_loop(event_loop, simple, 1, 2) self.assertIsInstance(d, Future) self.assertEqual(d._loop, event_loop) result = yield d self.assertEqual(result, 3) yield self.async.assertRaises(TypeError, run_in_loop, event_loop, simple, 1, 'a')
def __call__(self, consumer, testcls=None, tag=None): runner = consumer.worker.app.new_runner() if not isinstance(testcls, type): testcls = testcls() testcls.tag = tag testcls.cfg = consumer.worker.cfg all_tests = runner.loadTestsFromTestCase(testcls) num = all_tests.countTestCases() if num: if getattr(testcls, '_actor_execution', False): return run_in_loop(consumer.worker._loop, self.run_testcls, consumer, runner, testcls, all_tests) else: return self.run_testcls(consumer, runner, testcls, all_tests) else: return runner.result