Unit test dummy response functions.

This commit is contained in:
Aldo Cortesi 2013-02-23 16:34:59 +13:00
parent f203881b0d
commit 269780c577
3 changed files with 30 additions and 7 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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