aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_server.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/test_server.py b/test/test_server.py
index ba263e96..3686a6a8 100644
--- a/test/test_server.py
+++ b/test/test_server.py
@@ -1,3 +1,4 @@
+import socket, time
from netlib import tcp
from libpathod import pathoc
import tutils
@@ -80,3 +81,53 @@ class TestTransparent(tutils.TransparentProxTest, SanityMixin):
transparent = True
+class TestProxy(tutils.HTTPProxTest):
+ def test_http(self):
+ f = self.pathod("304")
+ assert f.status_code == 304
+
+ l = self.master.state.view[0]
+ assert l.request.client_conn.address
+ assert "host" in l.request.headers
+ assert l.response.code == 304
+
+ def test_response_timestamps(self):
+ # test that we notice at least 2 sec delay between timestamps
+ # in response object
+ f = self.pathod("304:b@1k:p50,2")
+ assert f.status_code == 304
+
+ response = self.master.state.view[0].response
+ assert 2 <= response.timestamp_end - response.timestamp_start <= 2.2
+
+ def test_request_timestamps(self):
+ # test that we notice at least 2 sec delay between timestamps
+ # in request object
+ connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ connection.connect(("127.0.0.1", self.proxy.port))
+
+ # call pathod server, wait a second to complete the request
+ connection.send("GET http://localhost:%d/p/304:b@1k HTTP/1.1\r\n"%self.server.port)
+ time.sleep(2.1)
+ connection.send("\r\n");
+ connection.recv(50000)
+ connection.close()
+
+ request, response = self.master.state.view[0].request, self.master.state.view[0].response
+ assert response.code == 304 # sanity test for our low level request
+ assert 2 <= request.timestamp_end - request.timestamp_start <= 2.2
+
+ def test_request_timestamps_not_affected_by_client_time(self):
+ # test that don't include user wait time in request's timestamps
+
+ f = self.pathod("304:b@10k")
+ assert f.status_code == 304
+ time.sleep(1)
+ f = self.pathod("304:b@10k")
+ assert f.status_code == 304
+
+ request = self.master.state.view[0].request
+ assert request.timestamp_end - request.timestamp_start <= 0.1
+
+ request = self.master.state.view[1].request
+ assert request.timestamp_end - request.timestamp_start <= 0.1