mirror of
https://github.com/django/daphne.git
synced 2024-11-21 15:36:33 +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 struct
|
||||
import subprocess
|
||||
|
@ -42,9 +43,10 @@ class DaphneTestingInstance:
|
|||
"""
|
||||
Finds an unused port to test stuff on
|
||||
"""
|
||||
for i in range(11200, 11300):
|
||||
if not self.port_in_use(i):
|
||||
return i
|
||||
for _ in range(100):
|
||||
port = random.randint(11200, 11300)
|
||||
if not self.port_in_use(port):
|
||||
return port
|
||||
raise RuntimeError("Cannot find a free port to test on")
|
||||
|
||||
def __enter__(self):
|
||||
|
@ -59,7 +61,7 @@ class DaphneTestingInstance:
|
|||
daphne_args += ["--proxy-headers"]
|
||||
# Start up process and make sure it begins listening.
|
||||
self.process = subprocess.Popen(daphne_args + ["daphne.test_application:TestApplication"])
|
||||
for _ in range(100):
|
||||
for _ in range(30):
|
||||
time.sleep(0.1)
|
||||
if self.port_in_use(self.port):
|
||||
return self
|
||||
|
|
Loading…
Reference in New Issue
Block a user