diff options
author | Ryan Petrello <lists@ryanpetrello.com> | 2012-12-06 16:12:32 -0500 |
---|---|---|
committer | Ryan Petrello <lists@ryanpetrello.com> | 2012-12-06 16:12:32 -0500 |
commit | cd17214ce49fa9bc453ed0abe23a4d7e9d37661c (patch) | |
tree | c7e7625991f56fb73dfd324a3f3b43d086c8ba36 /pecan/tests/test_scaffolds.py | |
parent | efac43b957dbff50ca77e41348af0257a344a7ac (diff) | |
download | pecan-cd17214ce49fa9bc453ed0abe23a4d7e9d37661c.tar.gz |
Improve a test that can fail due to a race condition.
Diffstat (limited to 'pecan/tests/test_scaffolds.py')
-rw-r--r-- | pecan/tests/test_scaffolds.py | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/pecan/tests/test_scaffolds.py b/pecan/tests/test_scaffolds.py index 44e6e99..0dc916c 100644 --- a/pecan/tests/test_scaffolds.py +++ b/pecan/tests/test_scaffolds.py @@ -4,10 +4,10 @@ import tempfile import shutil import subprocess import pkg_resources -import httplib import urllib2 import time from cStringIO import StringIO + import pecan if sys.version_info < (2, 7): @@ -220,9 +220,8 @@ class TestTemplateBuilds(unittest.TestCase): ]) def poll(self, proc): - limit = 5 + limit = 30 for i in range(limit): - time.sleep(1) proc.poll() # Make sure it's running @@ -230,6 +229,7 @@ class TestTemplateBuilds(unittest.TestCase): break elif i == limit: # pragma: no cover raise RuntimeError("pecan serve config.py didn't start.") + time.sleep(.1) @unittest.skipUnless(has_internet(), 'Internet connectivity unavailable.') @unittest.skipUnless( @@ -248,13 +248,23 @@ class TestTemplateBuilds(unittest.TestCase): try: self.poll(proc) - - # ...and that it's serving (valid) content... - conn = httplib.HTTPConnection('localhost:8080') - conn.request('GET', '/') - resp = conn.getresponse() - assert resp.status == 200 - assert 'This is a sample Pecan project.' in resp.read() + retries = 30 + while True: + retries -= 1 + if retries < 0: # pragma: nocover + raise RuntimeError( + "The HTTP server has not replied within 3 seconds." + ) + try: + # ...and that it's serving (valid) content... + resp = urllib2.urlopen('http://localhost:8080/') + assert resp.getcode() == 200 + assert 'This is a sample Pecan project.' in resp.read() + except urllib2.URLError: + pass + else: + break + time.sleep(.1) finally: proc.terminate() |