def test_timeout_reset(self):
     """ If the read timeout isn't set, socket timeout should reset """
     url = '/sleep?seconds=0.005'
     timeout = Timeout(connect=0.001)
     pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
     conn = pool._get_conn()
     try:
         yield From(pool._make_request(conn, 'GET', url))
     except ReadTimeoutError:
         self.fail("This request shouldn't trigger a read timeout.")
 def test_timeout_reset(self):
     """ If the read timeout isn't set, socket timeout should reset """
     url = "/sleep?seconds=0.005"
     timeout = Timeout(connect=0.001)
     pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
     conn = pool._get_conn()
     try:
         yield From(pool._make_request(conn, "GET", url))
     except ReadTimeoutError:
         self.fail("This request shouldn't trigger a read timeout.")
 def test_nagle(self):
     """ Test that connections have TCP_NODELAY turned on """
     # This test needs to be here in order to be run. socket.create_connection actually tries to
     # connect to the host provided so we need a dummyserver to be running.
     pool = HTTPConnectionPool(self.host, self.port)
     conn = pool._get_conn()
     yield From(pool._make_request(conn, 'GET', '/'))
     tcp_nodelay_setting = conn.sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY)
     assert tcp_nodelay_setting > 0, ("Expected TCP_NODELAY to be set on the "
                                      "socket (with value greater than 0) "
                                      "but instead was %s" %
                                      tcp_nodelay_setting)
    def test_tunnel(self):
        # note the actual httplib.py has no tests for this functionality
        timeout = Timeout(total=None)
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
        conn = pool._get_conn()
        try:
            conn.set_tunnel(self.host, self.port)
        except AttributeError: # python 2.6
            conn._set_tunnel(self.host, self.port)

        conn._tunnel = mock.Mock(return_value=None)
        yield From(pool._make_request(conn, 'GET', '/'))
        conn._tunnel.assert_called_once_with()

        # test that it's not called when tunnel is not set
        timeout = Timeout(total=None)
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
        conn = pool._get_conn()

        conn._tunnel = mock.Mock(return_value=None)
        yield From(pool._make_request(conn, 'GET', '/'))
        self.assertEqual(conn._tunnel.called, False)
    def test_tunnel(self):
        # note the actual httplib.py has no tests for this functionality
        timeout = Timeout(total=None)
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
        conn = pool._get_conn()
        try:
            conn.set_tunnel(self.host, self.port)
        except AttributeError:  # python 2.6
            conn._set_tunnel(self.host, self.port)

        conn._tunnel = mock.Mock(return_value=None)
        yield From(pool._make_request(conn, "GET", "/"))
        conn._tunnel.assert_called_once_with()

        # test that it's not called when tunnel is not set
        timeout = Timeout(total=None)
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
        conn = pool._get_conn()

        conn._tunnel = mock.Mock(return_value=None)
        yield From(pool._make_request(conn, "GET", "/"))
        self.assertEqual(conn._tunnel.called, False)
 def test_nagle(self):
     """ Test that connections have TCP_NODELAY turned on """
     # This test needs to be here in order to be run. socket.create_connection actually tries to
     # connect to the host provided so we need a dummyserver to be running.
     pool = HTTPConnectionPool(self.host, self.port)
     conn = pool._get_conn()
     yield From(pool._make_request(conn, "GET", "/"))
     tcp_nodelay_setting = conn.sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY)
     assert tcp_nodelay_setting > 0, (
         "Expected TCP_NODELAY to be set on the "
         "socket (with value greater than 0) "
         "but instead was %s" % tcp_nodelay_setting
     )