Skip to content

Commit 8dd9dc6

Browse files
hackaugustoLefterisJP
authored andcommitted
wait for the flask socket
1 parent 77ef64d commit 8dd9dc6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

raiden/tests/fixtures/api.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import os
66
import pytest
7+
import psutil
8+
import gevent
79
from gevent import Greenlet
810

911
from raiden.app import App
@@ -14,6 +16,17 @@
1416
from raiden.tests.utils.apitestcontext import ApiTestContext
1517

1618

19+
def wait_for_listening_port(port_number, tries=10, sleep=0.1):
20+
for _ in range(tries):
21+
gevent.sleep(sleep)
22+
connections = psutil.net_connections()
23+
for conn in connections:
24+
if conn.status == 'LISTEN' and conn.laddr[1] == port_number:
25+
return
26+
27+
raise RuntimeError('{port} is not bound'.format(port_number))
28+
29+
1730
# TODO: Figure out why this fixture can't work as session scoped
1831
# What happens is that after one test is done, in the next one
1932
# the server is no longer running even though the teardown has not
@@ -34,6 +47,11 @@ def api_backend(rest_api_port_number):
3447
use_evalex=False,
3548
)
3649

50+
# Fixes flaky test, were requests are done prior to the server initializing
51+
# the listening socket.
52+
# https://github.com/raiden-network/raiden/issues/389#issuecomment-305551563
53+
wait_for_listening_port(rest_api_port_number)
54+
3755
yield api_server, rest_api
3856

3957
server.kill(block=True, timeout=10)

0 commit comments

Comments
 (0)