27 lines
1.5 KiB
Python
27 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Verify the idle runner makes zero application requests, including preflight."""
|
|
import csv,json,subprocess,tempfile,threading
|
|
from pathlib import Path
|
|
from http.server import BaseHTTPRequestHandler,ThreadingHTTPServer
|
|
HERE=Path(__file__).parent
|
|
class Application(BaseHTTPRequestHandler):
|
|
requests=0
|
|
def do_GET(self):
|
|
type(self).requests+=1;self.send_response(500);self.end_headers()
|
|
do_POST=do_GET
|
|
def log_message(self,*args):pass
|
|
server=ThreadingHTTPServer(('127.0.0.1',0),Application)
|
|
threading.Thread(target=server.serve_forever,daemon=True).start()
|
|
try:
|
|
with tempfile.TemporaryDirectory(prefix='healthapp-idle-') as name:
|
|
out=Path(name)/'run'
|
|
result=subprocess.run(['python3',str(HERE/'run.py'),'idle','--host','127.0.0.1','--port',str(server.server_port),'--no-perfmon','--no-shelly','--warmup','1','--duration','3','--output',str(out)],capture_output=True,text=True)
|
|
assert result.returncode==0,result.stdout+result.stderr
|
|
data=json.loads((out/'run.json').read_text())
|
|
assert Application.requests==0 and data['http_samples']==0 and data['users']==0
|
|
assert data['measurement_end_ms']-data['measurement_start_ms']==3000
|
|
assert data['measurement_start_ms']-data['warmup_start_ms']==1000
|
|
with (out/'samples.csv').open() as f:assert all(not r['label'].startswith('HTTP ') for r in csv.DictReader(f))
|
|
print('Idle baseline passed: no application calls or login, no CA/accounts needed, warmup excluded')
|
|
finally:server.shutdown()
|