1
+ import os
2
+ import platform
1
3
import subprocess
2
- from time import sleep
3
4
import tempfile
4
- import platform
5
+ from time import sleep
5
6
6
7
import pytest
7
8
8
9
9
10
def _windows_kill_process (pid ):
10
11
import ctypes
12
+
11
13
PROCESS_TERMINATE = 1
12
14
handle = ctypes .windll .kernel32 .OpenProcess (PROCESS_TERMINATE , False , pid )
13
15
ctypes .windll .kernel32 .TerminateProcess (handle , - 1 )
14
16
ctypes .windll .kernel32 .CloseHandle (handle )
15
17
16
18
19
+ # NOTE: to run tests with a specific server binary,
20
+ # set the PATH such that it is the "aw-server" binary.
17
21
@pytest .fixture (scope = "session" )
18
22
def server_process ():
19
23
logfile_stdout = tempfile .NamedTemporaryFile (delete = False )
20
24
logfile_stderr = tempfile .NamedTemporaryFile (delete = False )
21
25
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
+ )
23
37
24
38
# Wait for server to start up properly
25
39
# TODO: Ping the server until it's alive to remove this sleep
@@ -40,19 +54,20 @@ def server_process():
40
54
with open (logfile_stdout .name , "r+b" ) as f :
41
55
stdout = str (f .read (), "utf8" )
42
56
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 } " )
44
58
45
59
with open (logfile_stderr .name , "r+b" ) as f :
46
60
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")
49
64
50
65
# Will show in case pytest fails
51
66
print (stderr )
52
67
53
68
for s in error_indicators :
54
69
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 } " )
56
71
57
72
# NOTE: returncode was -9 for whatever reason
58
73
# if server_proc.returncode != 0:
0 commit comments