11import fcntl
22import os
3+ import pathlib
34import shutil
45import signal
56import socket
67import subprocess
8+ import sys
79import tempfile
810import time
911from 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