Unit test dummy response functions.
This commit is contained in:
parent
f203881b0d
commit
269780c577
|
@ -194,7 +194,8 @@ class ProxyHandler(tcp.BaseHandler):
|
|||
sc.rfile.first_byte_timestamp, utils.timestamp()
|
||||
)
|
||||
response_reply = self.channel.ask(response)
|
||||
# Not replying to the server invalidates the server connection, so we terminate.
|
||||
# Not replying to the server invalidates the server
|
||||
# connection, so we terminate.
|
||||
if response_reply == KILL:
|
||||
sc.terminate()
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import socket, time
|
|||
from netlib import tcp
|
||||
from libpathod import pathoc
|
||||
import tutils, tservers
|
||||
from libmproxy import flow
|
||||
|
||||
"""
|
||||
Note that the choice of response code in these tests matters more than you
|
||||
|
@ -144,3 +145,18 @@ class TestProxy(tservers.HTTPProxTest):
|
|||
|
||||
request = self.master.state.view[1].request
|
||||
assert request.timestamp_end - request.timestamp_start <= 0.1
|
||||
|
||||
|
||||
class MasterFakeResponse(tservers.TestMaster):
|
||||
def handle_request(self, m):
|
||||
resp = tutils.tresp()
|
||||
m.reply(resp)
|
||||
|
||||
|
||||
class TestFakeResponse(tservers.HTTPProxTest):
|
||||
masterclass = MasterFakeResponse
|
||||
def test_kill(self):
|
||||
p = self.pathoc()
|
||||
f = self.pathod("200")
|
||||
assert "header_response" in f.headers.keys()
|
||||
|
||||
|
|
|
@ -29,16 +29,20 @@ class TestMaster(flow.FlowMaster):
|
|||
flow.FlowMaster.__init__(self, s, state)
|
||||
self.testq = testq
|
||||
|
||||
def handle(self, m):
|
||||
flow.FlowMaster.handle(self, m)
|
||||
def handle_request(self, m):
|
||||
flow.FlowMaster.handle_request(self, m)
|
||||
m.reply()
|
||||
|
||||
def handle_response(self, m):
|
||||
flow.FlowMaster.handle_response(self, m)
|
||||
m.reply()
|
||||
|
||||
|
||||
class ProxyThread(threading.Thread):
|
||||
def __init__(self, testq, config):
|
||||
self.tmaster = TestMaster(testq, config)
|
||||
controller.should_exit = False
|
||||
def __init__(self, tmaster):
|
||||
threading.Thread.__init__(self)
|
||||
self.tmaster = tmaster
|
||||
controller.should_exit = False
|
||||
|
||||
@property
|
||||
def port(self):
|
||||
|
@ -52,6 +56,7 @@ class ProxyThread(threading.Thread):
|
|||
|
||||
|
||||
class ProxTestBase:
|
||||
masterclass = TestMaster
|
||||
@classmethod
|
||||
def setupAll(cls):
|
||||
cls.tqueue = Queue.Queue()
|
||||
|
@ -61,7 +66,8 @@ class ProxTestBase:
|
|||
certfile=tutils.test_data.path("data/testkey.pem"),
|
||||
**pconf
|
||||
)
|
||||
cls.proxy = ProxyThread(cls.tqueue, config)
|
||||
tmaster = cls.masterclass(cls.tqueue, config)
|
||||
cls.proxy = ProxyThread(tmaster)
|
||||
cls.proxy.start()
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue