From 9526c5d56570652400929cc33f8fb36f361eecd6 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 7 Feb 2014 04:15:24 +0100 Subject: fix race conditions in test suite --- test/test_app.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'test/test_app.py') diff --git a/test/test_app.py b/test/test_app.py index 1ae81fc7..1046be20 100644 --- a/test/test_app.py +++ b/test/test_app.py @@ -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 -- cgit v1.2.3