Skip to content

Commit 08b74ab

Browse files
committed
ci update
1 parent 66731b5 commit 08b74ab

File tree

1 file changed

+23
-64
lines changed

1 file changed

+23
-64
lines changed

tests/conftest.py

Lines changed: 23 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import os
88
import sys
9+
import platform
910
import time
1011
import pytest
1112
import subprocess
@@ -47,74 +48,32 @@ def setup_stackql():
4748
# Return the StackQL instance for use in tests
4849
return stackql
4950

51+
def stackql_process_running():
52+
try:
53+
if platform.system() == "Windows":
54+
# Use `tasklist` to look for stackql.exe with correct port in args (may not include args, so fallback is loose match)
55+
output = subprocess.check_output(['tasklist', '/FI', 'IMAGENAME eq stackql.exe'], text=True)
56+
return "stackql.exe" in output
57+
else:
58+
# Use `ps aux` to search for 'stackql' process with the correct port
59+
output = subprocess.check_output(['ps', 'aux'], text=True)
60+
return f"--pgsrv.port={SERVER_PORT}" in output and "stackql" in output
61+
except subprocess.CalledProcessError:
62+
return False
63+
5064
@pytest.fixture(scope="session")
51-
def stackql_server(setup_stackql):
65+
def stackql_server():
5266
"""
53-
Session-level fixture to start and stop a StackQL server.
54-
This runs once for all tests that request it.
55-
56-
This improved version:
57-
1. Checks if a server is already running before starting one
58-
2. Uses process groups for better cleanup
59-
3. Handles errors more gracefully
67+
Verifies that a StackQL server process is running with the expected port.
68+
Does not attempt to start or stop the process.
6069
"""
61-
global server_process
62-
63-
# Check if server is already running
64-
print("\nChecking if server is running...")
65-
ps_output = subprocess.run(
66-
["ps", "aux"],
67-
capture_output=True,
68-
text=True
69-
).stdout
70-
71-
if "stackql" in ps_output and f"--pgsrv.port={SERVER_PORT}" in ps_output:
72-
print("Server is already running")
73-
# No need to start a server or set server_process
74-
else:
75-
# Start the server
76-
print(f"Starting stackql server on {SERVER_ADDRESS}:{SERVER_PORT}...")
77-
78-
# Get the registry setting from environment variable if available
79-
registry = os.environ.get('REG', '')
80-
registry_arg = f"--registry {registry}" if registry else ""
81-
82-
# Build the command
83-
cmd = f"{setup_stackql.bin_path} srv --pgsrv.address {SERVER_ADDRESS} --pgsrv.port {SERVER_PORT} {registry_arg}"
84-
85-
# Start the server process with process group for better cleanup
86-
server_process = subprocess.Popen(
87-
cmd,
88-
shell=True,
89-
stdout=subprocess.PIPE,
90-
stderr=subprocess.PIPE,
91-
preexec_fn=os.setsid # Use process group for cleaner termination
92-
)
93-
94-
# Wait for server to start
95-
print("Waiting for server to initialize...")
96-
time.sleep(5)
97-
98-
# Check if server started successfully
99-
if server_process.poll() is not None:
100-
# Process has terminated
101-
stdout, stderr = server_process.communicate()
102-
pytest.fail(f"Server failed to start: {stderr.decode()}")
103-
104-
# Yield to run tests
70+
print(f"\n🔍 Checking for running StackQL server process (port {SERVER_PORT})...")
71+
72+
if not stackql_process_running():
73+
pytest.exit(f"❌ No running StackQL server process found for port {SERVER_PORT}", returncode=1)
74+
75+
print("✅ StackQL server process is running.")
10576
yield
106-
107-
# Clean up server at the end if we started it
108-
if server_process and server_process.poll() is None:
109-
print("\nShutting down stackql server...")
110-
try:
111-
# Kill the entire process group
112-
os.killpg(os.getpgid(server_process.pid), signal.SIGTERM)
113-
server_process.wait(timeout=5)
114-
print("Server shutdown complete")
115-
except subprocess.TimeoutExpired:
116-
print("Server did not terminate gracefully, forcing shutdown...")
117-
os.killpg(os.getpgid(server_process.pid), signal.SIGKILL)
11877

11978
@pytest.fixture
12079
def mock_interactive_shell():

0 commit comments

Comments
 (0)