mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-04 07:47:27 +01:00
test(qa-only cleanup): refusal scenarios get a 1 s budget and an absolute worker deadline; 300 ms starved under parallel load
This commit is contained in:
1 parent
705e4a92af
commit
42fe9cdbef
2 files changed
+6
-4
No files matched your search
@@ -7,7 +7,8 @@ import { isAgentRecordGone, isOurAgent, readAgentRecord } from '../../browse/src
|
||||
|
||||
export async function stopQaOnlyBrowser(directory: string, timeoutMs: number): Promise<void> {
|
||||
if (!Number.isFinite(timeoutMs) || timeoutMs <= 100) throw new Error('QA-only browser cleanup: no settlement budget remains; retaining fixture');
|
||||
const worker = Bun.spawn([process.execPath, import.meta.path, directory, String(timeoutMs - 100)], {
|
||||
// An absolute deadline keeps worker startup inside its own budget, so it reports its reason before the kill.
|
||||
const worker = Bun.spawn([process.execPath, import.meta.path, directory, String(Date.now() + timeoutMs - 100)], {
|
||||
stdout: 'ignore', stderr: 'pipe',
|
||||
});
|
||||
let timedOut = false;
|
||||
@@ -21,8 +22,9 @@ export async function stopQaOnlyBrowser(directory: string, timeoutMs: number): P
|
||||
} finally { clearTimeout(timer); }
|
||||
}
|
||||
|
||||
async function settleOwnedBrowser(directory: string, timeoutMs: number): Promise<void> {
|
||||
async function settleOwnedBrowser(directory: string, deadlineEpochMs: number): Promise<void> {
|
||||
const started = performance.now();
|
||||
const timeoutMs = deadlineEpochMs - Date.now();
|
||||
const deadline = started + timeoutMs;
|
||||
let pending = ['identity verification'];
|
||||
const fail = (message: string): never => { throw new Error(`QA-only browser cleanup: ${message}`); };
|
||||
|
||||
@@ -114,8 +114,8 @@ Bun.spawnSync = (...args) => {
|
||||
const errors = { 'ack-only': 'settlement deadline exceeded', 'replaced-state': 'daemon state was replaced',
|
||||
'terminal-mismatch': 'terminal ownership is unconfirmed', 'chromium-mismatch': 'Chromium ownership is unconfirmed',
|
||||
'missing-terminal': 'terminal identity is unavailable', 'blocked-identity': 'owned worker settlement deadline exceeded' };
|
||||
await expect(stopQaOnlyBrowser(dir, 300)).rejects.toThrow(errors[scenario]);
|
||||
expect(performance.now() - started).toBeLessThan(1000);
|
||||
await expect(stopQaOnlyBrowser(dir, 1000)).rejects.toThrow(errors[scenario]);
|
||||
expect(performance.now() - started).toBeLessThan(2000);
|
||||
expect(daemon.exitCode).toBeNull();
|
||||
expect(readPidStartTime(chromiumPid)).not.toBe('');
|
||||
expect(fs.existsSync(stateFile)).toBe(true);
|
||||
|
||||
Reference in new issue
Block a user