1+ import os
2+ import platform
13import subprocess
2- from time import sleep
34import tempfile
4- import platform
5+ from time import sleep
56
67import pytest
78
89
910def _windows_kill_process (pid ):
1011 import ctypes
12+
1113 PROCESS_TERMINATE = 1
1214 handle = ctypes .windll .kernel32 .OpenProcess (PROCESS_TERMINATE , False , pid )
1315 ctypes .windll .kernel32 .TerminateProcess (handle , - 1 )
1416 ctypes .windll .kernel32 .CloseHandle (handle )
1517
1618
19+ # NOTE: to run tests with a specific server binary,
20+ # set the PATH such that it is the "aw-server" binary.
1721@pytest .fixture (scope = "session" )
1822def server_process ():
1923 logfile_stdout = tempfile .NamedTemporaryFile (delete = False )
2024 logfile_stderr = tempfile .NamedTemporaryFile (delete = False )
2125
22- server_proc = subprocess .Popen (["aw-server" , "--testing" ], stdout = logfile_stdout , stderr = logfile_stderr )
26+ # find the path of the "aw-server" binary and log it
27+ which_server = subprocess .check_output (["which" , "aw-server" ], text = True )
28+ print (f"aw-server path: { which_server } " )
29+
30+ # if aw-server-rust in PATH, assert that we're picking up the aw-server-rust binary
31+ if "aw-server-rust" in os .environ ["PATH" ]:
32+ assert "aw-server-rust" in which_server
33+
34+ server_proc = subprocess .Popen (
35+ ["aw-server" , "--testing" ], stdout = logfile_stdout , stderr = logfile_stderr
36+ )
2337
2438 # Wait for server to start up properly
2539 # TODO: Ping the server until it's alive to remove this sleep
@@ -40,19 +54,20 @@ def server_process():
4054 with open (logfile_stdout .name , "r+b" ) as f :
4155 stdout = str (f .read (), "utf8" )
4256 if any (e in stdout for e in error_indicators ):
43- pytest .fail ("Found ERROR indicator in stdout from server: {}" . format ( stdout ) )
57+ pytest .fail (f "Found ERROR indicator in stdout from server: { stdout } " )
4458
4559 with open (logfile_stderr .name , "r+b" ) as f :
4660 stderr = str (f .read (), "utf8" )
47- if not stderr :
48- pytest .fail ("No output to stderr from server" )
61+ # For some reason, this fails aw-server-rust, but not aw-server-python
62+ # if not stderr:
63+ # pytest.fail("No output to stderr from server")
4964
5065 # Will show in case pytest fails
5166 print (stderr )
5267
5368 for s in error_indicators :
5469 if s in stderr :
55- pytest .fail ("Found ERROR indicator in stderr from server: {}" . format ( s ) )
70+ pytest .fail (f "Found ERROR indicator in stderr from server: { s } " )
5671
5772 # NOTE: returncode was -9 for whatever reason
5873 # if server_proc.returncode != 0:
0 commit comments