Skip to content

Commit 6ebaaa8

Browse files
authored
Fix flaky policy server setup in smoke test (#7799)
* Debug smoke test policy server failure Signed-off-by: Aylei <[email protected]> * Update Signed-off-by: Aylei <[email protected]> * Fix Signed-off-by: Aylei <[email protected]> * Fix Signed-off-by: Aylei <[email protected]> --------- Signed-off-by: Aylei <[email protected]>
1 parent 32f7b47 commit 6ebaaa8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tests/conftest.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import fcntl
22
import os
3+
import pathlib
34
import shutil
45
import signal
56
import socket
67
import subprocess
8+
import sys
79
import tempfile
810
import time
911
from typing import List, Optional, Tuple
@@ -511,8 +513,9 @@ def setup_policy_server(request, tmp_path_factory):
511513
return
512514

513515
# get the temp directory shared by all workers
514-
root_tmp_dir = tmp_path_factory.getbasetemp().parent
516+
root_tmp_dir = tmp_path_factory.getbasetemp().parent / 'policy_server'
515517

518+
pathlib.Path(root_tmp_dir).mkdir(parents=True, exist_ok=True)
516519
fn = root_tmp_dir / 'policy_server.txt'
517520
policy_server_url = ''
518521
# Reference count and pid for cleanup
@@ -550,10 +553,18 @@ def wait_server(port: int, timeout: int = 60):
550553
if fn.is_file():
551554
ref_count(1)
552555
policy_server_url = fn.read_text().strip()
556+
print(
557+
f'Using existing policy server {policy_server_url}, file: {fn}',
558+
file=sys.stderr,
559+
flush=True)
553560
else:
554561
# Launch the policy server
555562
port = common_utils.find_free_port(start_port=10000)
556563
policy_server_url = f'http://127.0.0.1:{port}'
564+
print(
565+
f'Launching policy server {policy_server_url}, file: {fn}',
566+
file=sys.stderr,
567+
flush=True)
557568
server_process = subprocess.Popen([
558569
'python', 'tests/admin_policy/no_op_server.py', '--host',
559570
'0.0.0.0', '--port',
@@ -577,6 +588,7 @@ def wait_server(port: int, timeout: int = 60):
577588
pid = pid_file.read_text().strip()
578589
if pid:
579590
os.kill(int(pid), signal.SIGKILL)
591+
pathlib.Path(fn).unlink(missing_ok=True)
580592

581593

582594
@pytest.fixture(scope='session', autouse=True)

0 commit comments

Comments
 (0)