mirror of
https://github.com/django/daphne.git
synced 2024-11-22 07:56:34 +03:00
Make test port selection less flaky
This commit is contained in:
parent
9460cc166f
commit
b287a74236
|
@ -1,3 +1,4 @@
|
||||||
|
import random
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -42,9 +43,10 @@ class DaphneTestingInstance:
|
||||||
"""
|
"""
|
||||||
Finds an unused port to test stuff on
|
Finds an unused port to test stuff on
|
||||||
"""
|
"""
|
||||||
for i in range(11200, 11300):
|
for _ in range(100):
|
||||||
if not self.port_in_use(i):
|
port = random.randint(11200, 11300)
|
||||||
return i
|
if not self.port_in_use(port):
|
||||||
|
return port
|
||||||
raise RuntimeError("Cannot find a free port to test on")
|
raise RuntimeError("Cannot find a free port to test on")
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
|
@ -59,7 +61,7 @@ class DaphneTestingInstance:
|
||||||
daphne_args += ["--proxy-headers"]
|
daphne_args += ["--proxy-headers"]
|
||||||
# Start up process and make sure it begins listening.
|
# Start up process and make sure it begins listening.
|
||||||
self.process = subprocess.Popen(daphne_args + ["daphne.test_application:TestApplication"])
|
self.process = subprocess.Popen(daphne_args + ["daphne.test_application:TestApplication"])
|
||||||
for _ in range(100):
|
for _ in range(30):
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
if self.port_in_use(self.port):
|
if self.port_in_use(self.port):
|
||||||
return self
|
return self
|
||||||
|
|
Loading…
Reference in New Issue
Block a user