Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #75 from uber/bryce_flakes
Browse files Browse the repository at this point in the history
fix flakey example tests
  • Loading branch information
blampe committed Aug 4, 2015
2 parents 81c78ac + dcefbd5 commit dc300f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ hypothesis-pytest==0.12.0

# Integration test utilities
sh
psutil

# Test all the pythons
tox
Expand Down
25 changes: 10 additions & 15 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,22 @@
import subprocess

import pytest

try:
import __pypy__ # noqa
except ImportError:
PYPY = False
else:
PYPY = True
import psutil


@contextlib.contextmanager
def popen(path):
process = subprocess.Popen(
def popen(path, wait_for_listen=False):
process = psutil.Popen(
['python', path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
process.poll()

if wait_for_listen:
# It would be more correct to check ``conn.status ==
# psutil.CONN_LISTEN`` but this works
while process.is_running() and not process.connections():
pass

try:
yield process
Expand All @@ -62,7 +61,6 @@ def examples_dir():
os.chdir(cwd)


@pytest.mark.skipif(PYPY, reason='flaky in pypy')
@pytest.mark.parametrize(
'example_type',
[
Expand All @@ -86,10 +84,7 @@ def test_example(examples_dir, example_type):
example_type + 'client.py',
)

with popen(server_path):
# :(
import time
time.sleep(0.05)
with popen(server_path, wait_for_listen=True):
with popen(client_path) as client:
assert (
client.stdout.read() == 'Hello, world!\n'
Expand Down

0 comments on commit dc300f3

Please sign in to comment.