mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
fix race conditions in test suite
This commit is contained in:
parent
d07029d575
commit
9526c5d565
@ -1,6 +1,6 @@
|
||||
import mock, socket, os, sys
|
||||
import mock, socket, os, time
|
||||
from libmproxy import dump
|
||||
from netlib import certutils
|
||||
from netlib import certutils, tcp
|
||||
from libpathod.pathoc import Pathoc
|
||||
import tutils
|
||||
|
||||
@ -14,9 +14,16 @@ def get_free_port():
|
||||
|
||||
class AppTestMixin(object):
|
||||
def request(self, spec):
|
||||
p = Pathoc(("127.0.0.1", self.port))
|
||||
p.connect()
|
||||
return p.request(spec)
|
||||
t_start = time.time()
|
||||
while (time.time() - t_start) < 5:
|
||||
try:
|
||||
p = Pathoc(("127.0.0.1", self.port))
|
||||
p.connect() # might fail as the server might not be online yet.
|
||||
return p.request(spec)
|
||||
except tcp.NetLibError:
|
||||
time.sleep(0.01)
|
||||
assert False
|
||||
|
||||
|
||||
def test_basic(self):
|
||||
assert self.request("get:/").status_code == 200
|
||||
|
@ -80,7 +80,7 @@ class TestHTTPResponse:
|
||||
assert HTTPResponse.from_stream(s, "GET").code == 204
|
||||
|
||||
s = StringIO(_s)
|
||||
r = HTTPResponse.from_stream(s, "HEAD")
|
||||
r = HTTPResponse.from_stream(s, "HEAD") # HEAD must not have content by spec. We should leave it on the pipe.
|
||||
assert r.code == 200
|
||||
assert r.content == ""
|
||||
tutils.raises("Invalid server response: 'content", HTTPResponse.from_stream, s, "GET")
|
||||
tutils.raises("Invalid server response: 'content", HTTPResponse.from_stream, s, "GET")
|
||||
|
@ -86,13 +86,17 @@ class TestScript:
|
||||
f.reply = f.request.reply
|
||||
|
||||
with mock.patch("libmproxy.controller.DummyReply.__call__") as m:
|
||||
t_start = time.time()
|
||||
s.run("clientconnect", f)
|
||||
s.run("serverconnect", f)
|
||||
s.run("response", f)
|
||||
s.run("error", f)
|
||||
s.run("clientdisconnect", f)
|
||||
time.sleep(0.1)
|
||||
assert m.call_count == 5
|
||||
while (time.time() - t_start) < 1 and m.call_count <= 5:
|
||||
if m.call_count == 5:
|
||||
return
|
||||
time.sleep(0.001)
|
||||
assert False
|
||||
|
||||
def test_concurrent_err(self):
|
||||
s = flow.State()
|
||||
|
Loading…
Reference in New Issue
Block a user