コード例 #1
0
 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)
コード例 #2
0
ファイル: tests.py プロジェクト: rennat/pulsar
 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)
コード例 #3
0
ファイル: eventloop.py プロジェクト: JinsongBian/pulsar
    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"
コード例 #4
0
ファイル: eventloop.py プロジェクト: azazel75/pulsar
    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')
コード例 #5
0
ファイル: eventloop.py プロジェクト: axisofentropy/pulsar
    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')
コード例 #6
0
ファイル: case.py プロジェクト: robgil/pulsar
 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
コード例 #7
0
ファイル: case.py プロジェクト: axisofentropy/pulsar
 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