Skip to content

Commit

Permalink
To aid in debugging, save the output and print it if emulator does no…
Browse files Browse the repository at this point in the history
…t start in time
  • Loading branch information
another-rex committed Aug 9, 2024
1 parent 8385b0c commit 60bfd4f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions osv/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def start_datastore_emulator():
os.environ['DATASTORE_EMULATOR_HOST'] = 'localhost:' + port
os.environ['DATASTORE_PROJECT_ID'] = TEST_PROJECT_ID
os.environ['GOOGLE_CLOUD_PROJECT'] = TEST_PROJECT_ID
print(f"Emulator Port: {port}")
proc = subprocess.Popen([
'gcloud',
'beta',
Expand All @@ -128,21 +127,23 @@ def start_datastore_emulator():
_wait_for_emulator_ready(proc, 'datastore', _DATASTORE_READY_INDICATOR)
return proc

emulator_stdout_thread_output = ''

def _wait_for_emulator_ready(proc,
emulator,
indicator,
timeout=_EMULATOR_TIMEOUT):
"""Waits for emulator to be ready."""

emulator_stdout_thread_output = ''
def _read_thread(proc, ready_event):
"""Thread to continuously read from the process stdout."""
global emulator_stdout_thread_output
ready = False
while True:
line = proc.stdout.readline()
if not line:
break
print(line)
emulator_stdout_thread_output += str(line) + '\n'
if not ready and indicator in line:
ready = True
ready_event.set()
Expand All @@ -154,6 +155,7 @@ def _read_thread(proc, ready_event):
thread.start()

if not ready_event.wait(timeout):
print(emulator_stdout_thread_output)
raise RuntimeError(
'{} emulator did not get ready in time.'.format(emulator))

Expand Down

0 comments on commit 60bfd4f

Please sign in to comment.