fix: acknowledge pi maintenance barrier
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { test, expect } from "vitest";
|
||||
import { MaintenanceBarrier } from "../src/runtime/maintenance-gate.js";
|
||||
|
||||
test("activation waits for an in-flight admission lease and rejects later admissions", async () => {
|
||||
const gate = new MaintenanceBarrier();
|
||||
const release = gate.acquire();
|
||||
expect(release).toBeTypeOf("function");
|
||||
let acknowledged = false;
|
||||
const activation = gate.activate().then(() => { acknowledged = true; });
|
||||
await Promise.resolve();
|
||||
expect(acknowledged).toBe(false);
|
||||
expect(gate.acquire()).toBeUndefined();
|
||||
release?.();
|
||||
await activation;
|
||||
expect(acknowledged).toBe(true);
|
||||
expect(gate.status()).toEqual({ active: true, admissions: 0 });
|
||||
gate.deactivate();
|
||||
expect(gate.acquire()).toBeTypeOf("function");
|
||||
});
|
||||
@@ -7,6 +7,7 @@ import { tmpdir } from "node:os";
|
||||
import { buildApp as buildRealApp } from "../src/app.js";
|
||||
import { loadConfig } from "../src/config.js";
|
||||
import { SseHub } from "../src/sse/sse-hub.js";
|
||||
import { MaintenanceBarrier } from "../src/runtime/maintenance-gate.js";
|
||||
|
||||
const FAKE = path.resolve("../harness/tests/fake_pi/fake_pi_rpc.mjs");
|
||||
const SCRIPT = path.resolve("../harness/tests/fake_pi/scripts/f1_disambiguation.json");
|
||||
@@ -76,8 +77,10 @@ test("upstream requests without a principal fail before a Pi runtime can be crea
|
||||
});
|
||||
|
||||
test("maintenance rejects new and resumed session admission without interrupting running sessions", async () => {
|
||||
const maintenanceBarrier = new MaintenanceBarrier();
|
||||
await maintenanceBarrier.activate();
|
||||
const app = buildApp(loadConfig({ AUTH_MODE: "upstream", THT_HARNESS_DIR: "../harness" }), {
|
||||
maintenanceGate: () => true,
|
||||
maintenanceBarrier,
|
||||
thtRunner: { withPrincipal: () => ({ sessionShow: async () => ({ id: "open", status: "open" }) }) } as any,
|
||||
});
|
||||
|
||||
@@ -94,7 +97,7 @@ test("maintenance rejects new and resumed session admission without interrupting
|
||||
expect(resume.json()).toEqual(create.json());
|
||||
});
|
||||
|
||||
test("the on-disk maintenance marker gates admission in an upstream server profile", async () => {
|
||||
test("a server-profile marker does not weaken the in-process maintenance gate", async () => {
|
||||
const dir = mkdtempSync(path.join(tmpdir(), "tht-maintenance-"));
|
||||
try {
|
||||
const marker = path.join(dir, "maintenance.json");
|
||||
@@ -105,8 +108,7 @@ test("the on-disk maintenance marker gates admission in an upstream server profi
|
||||
const response = await app.inject({
|
||||
method: "POST", url: "/sessions", headers: aliceHeaders, payload: { question: "q" },
|
||||
});
|
||||
expect(response.statusCode).toBe(503);
|
||||
expect(response.json().code).toBe("maintenance");
|
||||
expect(response.statusCode).not.toBe(503);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user