Skip to content

Commit

Permalink
server: test: display server logs in case of failure
Browse files Browse the repository at this point in the history
  • Loading branch information
phymbert committed Feb 23, 2024
1 parent 54ea4d4 commit 5b2ce45
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion examples/server/tests/features/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import multiprocessing
import os
import socket
import subprocess
Expand All @@ -17,6 +16,16 @@ def before_scenario(context, scenario):


def after_scenario(context, scenario):
if scenario.status == "failed":
print(f"\x1b[33;101mSCENARIO FAILED: {scenario.name} server logs:\x1b[0m\n\n")
if os.path.isfile('llama.log'):
with closing(open('llama.log', 'r')) as f:
for line in f:
print(line)

if not pid_exists(context.server_process.pid):
assert False, f"Server not running pid={context.server_process.pid} ..."

print(f"stopping server pid={context.server_process.pid} ...")
context.server_process.kill()
# Wait few for socket to free up
Expand All @@ -40,3 +49,16 @@ def is_server_listening(server_fqdn, server_port):
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
result = sock.connect_ex((server_fqdn, server_port))
return result == 0


def pid_exists(pid):
"""Check whether pid exists in the current process table."""
import errno
if pid < 0:
return False
try:
os.kill(pid, 0)
except OSError as e:
return e.errno == errno.EPERM
else:
return True

0 comments on commit 5b2ce45

Please sign in to comment.