예제 #1
0
class TestingHttpServerTestCase(TestCase):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.assertIsNotNone(self.request_handler)
        self.server_address = ('127.0.0.1', random.randint(65000, 65535))
        self.server_process = ForkProcess(target=TestingHTTPServer.run_server,
                                          args=(self.server_address, self.request_handler))

    def setUp(self):
        self.server_process.start()
        self.wait_for_server()

    def wait_for_server(self):
        while True:
            try:
                with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
                    s.connect(self.server_address)
            except Exception:
                time.sleep(.25)
            else:
                break

    def tearDown(self):
        self.server_process.terminate()

    def clientWithKwargs(self, **kwargs):
        return Client(["%s:%d" % self.server_address], timeout=1, **kwargs)
예제 #2
0
class KeepAliveClientTest(TestCase):

    server_address = ("127.0.0.1", 65535)

    def __init__(self, *args, **kwargs):
        super(KeepAliveClientTest, self).__init__(*args, **kwargs)
        self.server_process = ForkProcess(target=self._run_server)

    def setUp(self):
        super(KeepAliveClientTest, self).setUp()
        self.client = Client(["%s:%d" % self.server_address])
        self.server_process.start()
        time.sleep(.10)

    def tearDown(self):
        self.server_process.terminate()
        self.client.close()
        super(KeepAliveClientTest, self).tearDown()

    def _run_server(self):
        self.server = HTTPServer(self.server_address,
                                 ClientAddressRequestHandler)
        self.server.handle_request()

    def test_client_keepalive(self):
        for x in range(10):
            result = self.client.sql("select * from fake")

            another_result = self.client.sql("select again from fake")
            self.assertEqual(result, another_result)
예제 #3
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.assertIsNotNone(self.request_handler)
     self.server_address = ('127.0.0.1', random.randint(65000, 65535))
     self.server_process = ForkProcess(target=TestingHTTPServer.run_server,
                                       args=(self.server_address,
                                             self.request_handler))
예제 #4
0
 def __init__(self, *args, **kwargs):
     super(KeepAliveClientTest, self).__init__(*args, **kwargs)
     self.server_process = ForkProcess(target=self._run_server)