"""Exercise actual OS locks/processes, without starting inference or touching GPUs.""" from concurrent.futures import ThreadPoolExecutor from pathlib import Path import os import subprocess import sys import threading import time import pytest from common import write_json from controller.seed_service import identity from test_release_integration import ROOT CHILD=''' import sys,time from pathlib import Path sys.path.insert(0,sys.argv[1]) from project_paths import initialize initialize() from common import read_json from controller.service_lease import service_lease with service_lease(read_json(sys.argv[2]),sys.argv[3]): Path(sys.argv[4]).write_text('ready') deadline=time.monotonic()+8 while not Path(sys.argv[5]).exists(): if time.monotonic()>deadline:raise RuntimeError('test gate timeout') time.sleep(.02) ''' @pytest.mark.parametrize('same_endpoint',[False,True]) def test_student_endpoint_leases_allow_independent_processes_only(tmp_path,config,same_endpoint): cfg=tmp_path/'config.json';write_json(cfg,config) release=tmp_path/'release';children=[];logs=[] def launch(i,endpoint): spec=tmp_path/f'lane-{i}.json' train_lock=str(tmp_path/'train.lock') write_json(spec,{'schema_version':2,'owner':identity(os.getpid()),'seed':i, 'student_endpoint':endpoint,'training_lock':train_lock}) env={**os.environ,'RSI_SUITE_LANE_SPEC':str(spec),'DECICO_RSI_API_BASE':endpoint, 'DECICO_RSI_TRAIN_LOCK':train_lock,'PYTHONDONTWRITEBYTECODE':'1'} env.pop('RSI_SERVICE_LOCK_FD',None) log=(tmp_path/f'child-{i}.log').open('w');logs.append(log) child=subprocess.Popen([sys.executable,'-B','-c',CHILD,str(ROOT/'decico_rsi'),str(cfg), str(tmp_path/f'lease-{i}'),str(tmp_path/f'ready-{i}'),str(release)], cwd=ROOT,env=env,stdout=log,stderr=subprocess.STDOUT) children.append(child) def ready(i): deadline=time.monotonic()+4 while not (tmp_path/f'ready-{i}').exists(): assert children[i].poll() is None,(tmp_path/f'child-{i}.log').read_text() assert time.monotonic()