Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions osv/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import difflib
import os
import shutil
import socket
import pprint
import signal
import time
Expand Down Expand Up @@ -295,17 +296,23 @@ def setup_gitter():
)

try:
# Wait a bit for it to start (optional, but good for stability)
# Basic check to see if it crashed immediately
try:
proc.wait(timeout=1.0)
# If it returns, it exited
raise RuntimeError(
f'Gitter exited early:\n{proc.stdout.read().decode()}\n\n'
f'{proc.stderr.read().decode()}')
except subprocess.TimeoutExpired:
# Process is still running
pass
# Wait for it to start
start = time.time()
while time.time() - start < 60:
if proc.poll() is not None:
# If it returns, it exited
raise RuntimeError(
f'Gitter exited early:\n{proc.stdout.read().decode()}\n\n'
f'{proc.stderr.read().decode()}')

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
if s.connect_ex(('localhost', int(gitter_port))) == 0:
print(f'Gitter ready in {time.time() - start:.2f}s.')
break
time.sleep(0.5)
else:
os.killpg(os.getpgid(proc.pid), signal.SIGKILL)
raise RuntimeError('Gitter did not get ready in time.')

yield

Expand Down
Loading