feat(http): liveness and readiness probes with a drain window (CARD-17, #115)
createApp({ health: true }) serves GET/HEAD /__live__ and /__ready__.
Ready reports booting until boot() resolves, ok or degraded (from
app.degraded()) after that, and draining from the moment close() starts.
Probes are answered by the adapters, ahead of the request gate and of
handle(): Node in serve() (src/http/server.ts), the Fetch path in
app.fetch before it awaits the boot. Otherwise ready could never say
booting. Being ahead of the gate means maxConcurrentRequests never sheds
a probe (D14). Being ahead of handle() means no step, provider, plugin or
onError runs, and no lifecycle event is emitted, so logRequests and
metrics never see a probe. Security headers still apply, plus
cache-control: no-store. Other methods get 405 with Allow: GET, HEAD.
A probe through app.fetch before any boot starts the boot without
awaiting it. On the edge, or under a bare Deno.serve(app.fetch), nothing
else may boot the app, and an orchestrator that waits for ready before
sending traffic would wait forever.
health: { drainDelayMs } (D14) marks the app draining and keeps the
listener open for that long before connections drain. Without it, Node
closes idle keep-alive sockets at once, and a probe sees a reset rather
than the 503. The window is spent out of the close budget. serveDeno and
serveBun start the same window, through a symbol-keyed hook on the app,
before server.shutdown() / server.stop(false). workerd has no close(),
so it never reports draining.
While health is on, /__live__ and /__ready__ join the reserved-path
boot check that CARD-21 introduced, for local and mesh-spliced routes.
Invalid health values throw at createApp.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
15 files changed
+792
-12
No files matched your search
@@ -97,3 +97,24 @@ test('serveBun rejects when a provider fails, instead of binding a port that 500
|
||||
|
||||
await expect(serveBun(app, { port: 0 })).rejects.toThrow(/no such key file/);
|
||||
});
|
||||
|
||||
// CARD-17 T5 (D14): close() marks the app draining before the server stops, and the drain window
|
||||
// keeps the listener open long enough for a probe to read the 503.
|
||||
test('serveBun close() with health.drainDelayMs: /__ready__ 503 draining, in-flight request 200', async () => {
|
||||
const app = createApp({ modules: [M], health: { drainDelayMs: 300 } });
|
||||
const server = await serveBun(app, { port: 0 });
|
||||
const base = `http://127.0.0.1:${server.port}`;
|
||||
|
||||
expect((await fetch(`${base}/__ready__`)).status).toBe(200);
|
||||
|
||||
const inFlight = fetch(`${base}/slow`).then((r) => r.json());
|
||||
await Bun.sleep(50);
|
||||
|
||||
const closing = server.close({ timeoutMs: 5000 });
|
||||
const probe = await fetch(`${base}/__ready__`);
|
||||
expect(probe.status).toBe(503);
|
||||
expect(await probe.json()).toEqual({ status: 'draining' });
|
||||
|
||||
expect(await inFlight).toEqual({ ok: true });
|
||||
await closing;
|
||||
});
|
||||
@@ -121,3 +121,29 @@ Deno.test('serveDeno rejects when a provider fails, instead of binding a port th
|
||||
throw new Error(`expected serveDeno to reject with the provider's error, got: ${message || '<resolved>'}`);
|
||||
}
|
||||
});
|
||||
|
||||
// CARD-17 T5 (D14): close() marks the app draining before the server shuts down, and the drain window
|
||||
// keeps the listener open long enough for a probe to read the 503.
|
||||
Deno.test('serveDeno close() with health.drainDelayMs: /__ready__ 503 draining, in-flight request 200', async () => {
|
||||
const app = createApp({ modules: [M], health: { drainDelayMs: 300 } });
|
||||
const server = await serveDeno(app, { port: 0, onListen: () => {} });
|
||||
const base = `http://127.0.0.1:${portOf(server)}`;
|
||||
|
||||
const ready = await fetch(`${base}/__ready__`);
|
||||
if (ready.status !== 200) throw new Error(`ready before close: ${ready.status}`);
|
||||
await ready.body?.cancel();
|
||||
|
||||
const inFlight = fetch(`${base}/slow`).then((r) => r.json());
|
||||
await new Promise((r) => setTimeout(r, 50));
|
||||
|
||||
const closing = server.close({ timeoutMs: 5000 });
|
||||
const probe = await fetch(`${base}/__ready__`);
|
||||
const body = await probe.json();
|
||||
if (probe.status !== 503 || body.status !== 'draining') {
|
||||
throw new Error(`probe during close: ${probe.status} ${JSON.stringify(body)}`);
|
||||
}
|
||||
|
||||
const done = await inFlight;
|
||||
if (done.ok !== true) throw new Error(`in-flight request was cut: ${JSON.stringify(done)}`);
|
||||
await closing;
|
||||
});
|
||||
+20
-1
@@ -148,8 +148,27 @@ async function main() {
|
||||
assert.equal(reservedRes.status, 500);
|
||||
assert.match(await reservedRes.text(), /^route @Ws \/__mesh__\/control at Claims\.control uses the reserved path/);
|
||||
|
||||
// CARD-17 T10: live 200; ready booting → ok, with only probes reaching the isolate. There is no
|
||||
// close() on workerd, so draining is never reported here (documented, not tested for). Any probe
|
||||
// starts the boot, so ready is asked first to see `booting`.
|
||||
const first = await mf.dispatchFetch('http://health/__ready__');
|
||||
assert.equal(first.status, 503);
|
||||
assert.deepEqual(await first.json(), { status: 'booting' });
|
||||
const live = await mf.dispatchFetch('http://health/__live__');
|
||||
assert.equal(live.status, 200);
|
||||
assert.deepEqual(await live.json(), { status: 'ok' });
|
||||
let ready = await mf.dispatchFetch('http://health/__ready__');
|
||||
for (let i = 0; i < 20 && ready.status !== 200; i++) {
|
||||
await ready.arrayBuffer();
|
||||
await new Promise((resolve) => setTimeout(resolve, 25));
|
||||
ready = await mf.dispatchFetch('http://health/__ready__');
|
||||
}
|
||||
assert.equal(ready.status, 200);
|
||||
assert.deepEqual(await ready.json(), { status: 'ok' });
|
||||
assert.equal(ready.headers.get('cache-control'), 'no-store');
|
||||
|
||||
console.log(
|
||||
'edge (workerd via miniflare): HTTP 200 + body limits 413/413/200/413 + WS echo:hi + ws limits + reserved path — PASS',
|
||||
'edge (workerd via miniflare): HTTP 200 + body limits 413/413/200/413 + WS echo:hi + ws limits + reserved path + health — PASS',
|
||||
);
|
||||
} finally {
|
||||
await mf.dispose();
|
||||
|
||||
+5
-2
@@ -49,7 +49,9 @@ class M {}
|
||||
const app = createApp({ modules: [M] });
|
||||
// #107: the same graph with tight ws limits, reached through the `limited` host.
|
||||
const limited = createApp({ modules: [M], limits: { maxWsMessageBytes: 1024, maxWsQueue: 4 } });
|
||||
const handlers = { default: edgeHandler(app), limited: edgeHandler(limited) };
|
||||
// CARD-17 T10: health probes, reached through the `health` host. Never booted by anything but probes.
|
||||
const healthy = createApp({ modules: [M], health: true });
|
||||
const handlers = { default: edgeHandler(app), limited: edgeHandler(limited), health: edgeHandler(healthy) };
|
||||
|
||||
// CARD-21 (D17): a route on the reserved mesh path must fail createApp inside workerd too. Built per
|
||||
// request on the `reserved` host so a regression answers with a status instead of breaking the worker.
|
||||
@@ -76,6 +78,7 @@ export default {
|
||||
fetch: (request: Request, env?: unknown, ctx?: Parameters<typeof handlers.default>[2]) => {
|
||||
const host = new URL(request.url).hostname;
|
||||
if (host === 'reserved') return reservedBoot();
|
||||
return (host === 'limited' ? handlers.limited : handlers.default)(request, env, ctx);
|
||||
const handler = host === 'limited' ? handlers.limited : host === 'health' ? handlers.health : handlers.default;
|
||||
return handler(request, env, ctx);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,389 @@
|
||||
/**
|
||||
* CARD-17 (#115, D14): `createApp({ health })` serves `/__live__` and `/__ready__` outside the pipeline,
|
||||
* with booting / ok / degraded / draining states and a drain window on close(). Deno and Bun repeat
|
||||
* the drain case (T5) in their own suites; workerd covers T10 in `test/edge/run.ts`.
|
||||
*/
|
||||
import 'reflect-metadata';
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest';
|
||||
import http from 'http';
|
||||
import type { AddressInfo } from 'net';
|
||||
import { WebSocketServer } from 'ws';
|
||||
import { createApp, Route, Get, Ws, Module, Provider } from '../src/index';
|
||||
import type { Logger } from '../src/logger';
|
||||
import type { Plugin } from '../src/plugin';
|
||||
import { encode, decode, MESH_PROTOCOL_VERSION } from '../src/mesh/protocol';
|
||||
|
||||
const silentLogger = (): Logger => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() });
|
||||
const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
let releaseSlow: () => void = () => {};
|
||||
|
||||
@Route('/')
|
||||
class Ctl {
|
||||
@Get('/ping') ping() {
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
// Held open until the test releases it: an in-flight request across close().
|
||||
@Get('/slow') async slow() {
|
||||
await new Promise<void>((resolve) => (releaseSlow = resolve));
|
||||
return { slow: true };
|
||||
}
|
||||
}
|
||||
|
||||
@Module({ mountpoint: '/', controllers: [Ctl] })
|
||||
class M {}
|
||||
|
||||
type AppOpts = Parameters<typeof createApp>[0];
|
||||
const make = (extra: Partial<AppOpts> = {}) => createApp({ modules: [M], logger: silentLogger(), ...extra });
|
||||
|
||||
async function probe(app: ReturnType<typeof createApp>, path: string, method = 'GET') {
|
||||
const res = await app.fetch(new Request(`http://x${path}`, { method }));
|
||||
const text = await res.text();
|
||||
return { status: res.status, body: text ? JSON.parse(text) : undefined, headers: res.headers };
|
||||
}
|
||||
|
||||
describe('CARD-17: health probes through app.fetch', () => {
|
||||
it('T1: /__ready__ is 503 booting while a slow provider boots, /__live__ is 200', async () => {
|
||||
let finish: () => void = () => {};
|
||||
|
||||
@Provider({ provides: 'slowDb' })
|
||||
class SlowDb {
|
||||
async provide() {
|
||||
await new Promise<void>((resolve) => (finish = resolve));
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/', controllers: [Ctl], providers: [SlowDb] })
|
||||
class Slow {}
|
||||
|
||||
const app = createApp({ modules: [Slow], health: true, logger: silentLogger() });
|
||||
const booting = app.boot();
|
||||
await sleep(10);
|
||||
|
||||
expect(await probe(app, '/__ready__')).toMatchObject({ status: 503, body: { status: 'booting' } });
|
||||
expect(await probe(app, '/__live__')).toMatchObject({ status: 200, body: { status: 'ok' } });
|
||||
|
||||
finish();
|
||||
await booting;
|
||||
expect(await probe(app, '/__ready__')).toMatchObject({ status: 200, body: { status: 'ok' } });
|
||||
});
|
||||
|
||||
it('T1: a probe before any boot starts the boot without waiting for it', async () => {
|
||||
let started = false;
|
||||
|
||||
@Provider({ provides: 'watched' })
|
||||
class Watched {
|
||||
provide() {
|
||||
started = true;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/', controllers: [Ctl], providers: [Watched] })
|
||||
class W {}
|
||||
|
||||
const app = createApp({ modules: [W], health: true, logger: silentLogger() });
|
||||
expect((await probe(app, '/__ready__')).body).toEqual({ status: 'booting' });
|
||||
await sleep(10);
|
||||
expect(started).toBe(true);
|
||||
expect((await probe(app, '/__ready__')).body).toEqual({ status: 'ok' });
|
||||
});
|
||||
|
||||
it('a failed boot keeps /__ready__ at 503 booting and still fails real requests', async () => {
|
||||
@Provider({ provides: 'broken' })
|
||||
class Broken {
|
||||
provide(): never {
|
||||
throw new Error('no pool');
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/', controllers: [Ctl], providers: [Broken] })
|
||||
class B {}
|
||||
|
||||
const app = createApp({ modules: [B], health: true, logger: silentLogger() });
|
||||
await probe(app, '/__ready__');
|
||||
await sleep(10);
|
||||
expect(await probe(app, '/__ready__')).toMatchObject({ status: 503, body: { status: 'booting' } });
|
||||
await expect(app.fetch(new Request('http://x/ping'))).rejects.toThrow("provider 'broken' failed: no pool");
|
||||
});
|
||||
|
||||
it('T2: booted with nothing degraded → 200 ok', async () => {
|
||||
const app = make({ health: true });
|
||||
await app.boot();
|
||||
expect(await probe(app, '/__ready__')).toMatchObject({ status: 200, body: { status: 'ok' } });
|
||||
});
|
||||
|
||||
it('T3: an optional provider failed → 200 degraded with its name', async () => {
|
||||
@Provider({ provides: 'x', optional: true })
|
||||
class X {
|
||||
provide(): never {
|
||||
throw new Error('down');
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/', controllers: [Ctl], providers: [X] })
|
||||
class D {}
|
||||
|
||||
const app = createApp({ modules: [D], health: true, logger: silentLogger() });
|
||||
await app.boot();
|
||||
expect(await probe(app, '/__ready__')).toMatchObject({
|
||||
status: 200,
|
||||
body: { status: 'degraded', degraded: ['x'] },
|
||||
});
|
||||
});
|
||||
|
||||
it('T7: POST /__ready__ → 405 with Allow: GET, HEAD; HEAD answers with no body', async () => {
|
||||
const app = make({ health: true });
|
||||
await app.boot();
|
||||
|
||||
const post = await probe(app, '/__ready__', 'POST');
|
||||
expect(post.status).toBe(405);
|
||||
expect(post.headers.get('allow')).toBe('GET, HEAD');
|
||||
|
||||
const head = await probe(app, '/__live__', 'HEAD');
|
||||
expect(head.status).toBe(200);
|
||||
expect(head.body).toBeUndefined();
|
||||
});
|
||||
|
||||
it('security headers are injected, cache-control is no-store, a query string is ignored', async () => {
|
||||
const app = make({ health: true });
|
||||
await app.boot();
|
||||
const res = await probe(app, '/__ready__?verbose=1');
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.headers.get('cache-control')).toBe('no-store');
|
||||
expect(res.headers.get('x-content-type-options')).toBe('nosniff');
|
||||
});
|
||||
|
||||
it('T9 + rule 5: no lifecycle event, no plugin step, no log line for a probe', async () => {
|
||||
const step = vi.fn(() => ({}));
|
||||
const plugin: Plugin = {
|
||||
name: 'global-step',
|
||||
mount(api) {
|
||||
api.scope.add({ kind: 'step', name: 'everywhere', needs: [], provides: [], run: step });
|
||||
},
|
||||
};
|
||||
const logger = silentLogger();
|
||||
const app = createApp({ modules: [M], plugins: [plugin], health: true, logRequests: true, logger });
|
||||
await app.boot();
|
||||
const emit = vi.spyOn(app.bus, 'emit');
|
||||
|
||||
for (let i = 0; i < 10; i++) await probe(app, i % 2 ? '/__live__' : '/__ready__');
|
||||
|
||||
expect(emit).not.toHaveBeenCalled();
|
||||
expect(step).not.toHaveBeenCalled();
|
||||
expect(logger.info).not.toHaveBeenCalled();
|
||||
|
||||
// the control: an ordinary request does run the step and log
|
||||
await app.fetch(new Request('http://x/ping'));
|
||||
expect(step).toHaveBeenCalled();
|
||||
expect(logger.info).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('T6: probes answer while maxConcurrentRequests sheds everything else', async () => {
|
||||
const app = make({ health: true, limits: { maxConcurrentRequests: 1 } });
|
||||
await app.boot();
|
||||
const held = app.fetch(new Request('http://x/slow'));
|
||||
await sleep(10);
|
||||
|
||||
expect((await app.fetch(new Request('http://x/ping'))).status).toBe(503);
|
||||
expect((await probe(app, '/__ready__')).status).toBe(200);
|
||||
expect((await probe(app, '/__live__')).status).toBe(200);
|
||||
|
||||
releaseSlow();
|
||||
expect((await held).status).toBe(200);
|
||||
});
|
||||
|
||||
it('health off: the probe paths are ordinary paths (404)', async () => {
|
||||
const app = make();
|
||||
expect((await app.fetch(new Request('http://x/__ready__'))).status).toBe(404);
|
||||
});
|
||||
|
||||
it('draining after close() on an app served through app.fetch', async () => {
|
||||
const app = make({ health: true });
|
||||
await app.boot();
|
||||
await app.close();
|
||||
expect(await probe(app, '/__ready__')).toMatchObject({ status: 503, body: { status: 'draining' } });
|
||||
expect((await probe(app, '/__live__')).status).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe('CARD-17: health option validation and reserved paths', () => {
|
||||
it('invalid health values throw at createApp', () => {
|
||||
expect(() => make({ health: 'yes' as never })).toThrow(/health must be true, false or \{ drainDelayMs/);
|
||||
expect(() => make({ health: { drainDelayMs: -1 } })).toThrow(/drainDelayMs must be a non-negative number/);
|
||||
expect(() => make({ health: { drainDelayMs: Number.NaN } })).toThrow(/non-negative number/);
|
||||
expect(() => make({ health: { checks: [] } as never })).toThrow(/unknown option 'checks'/);
|
||||
expect(() => make({ health: { drainDelayMs: 20_000 } })).toThrow(/cannot exceed shutdownTimeoutMs \(10000\)/);
|
||||
expect(() => make({ health: { drainDelayMs: 600 }, shutdownTimeoutMs: 1000, teardownTimeoutMs: 500 })).toThrow(
|
||||
/plus teardownTimeoutMs \(500\)/,
|
||||
);
|
||||
expect(() => make({ health: { drainDelayMs: 500 } })).not.toThrow();
|
||||
expect(() => make({ health: false })).not.toThrow();
|
||||
});
|
||||
|
||||
it('T8: @Get(/__live__) with health on fails createApp, naming the route', () => {
|
||||
@Route('/')
|
||||
class Own {
|
||||
@Get('/__live__') live() {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/', controllers: [Own] })
|
||||
class O {}
|
||||
|
||||
expect(() => createApp({ modules: [O], health: true })).toThrow(
|
||||
'route GET /__live__ at Own.live uses the reserved path /__live__ (the liveness probe, health: true) — ' +
|
||||
'green-tea answers that path itself on every runtime, so no route may declare it. Move the route.',
|
||||
);
|
||||
});
|
||||
|
||||
it('a route at /__ready__ (HTTP or WS) fails with health on and serves with it off', async () => {
|
||||
@Route('/')
|
||||
class Own {
|
||||
@Get('/__ready__') ready() {
|
||||
return { mine: true };
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/', controllers: [Own] })
|
||||
class O {}
|
||||
@Route('/')
|
||||
class OwnWs {
|
||||
@Ws('/__ready__') ready() {
|
||||
return (async function* () {})();
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/', controllers: [OwnWs] })
|
||||
class OW {}
|
||||
|
||||
expect(() => createApp({ modules: [O], health: true })).toThrow(/^route GET \/__ready__ at Own\.ready uses/);
|
||||
expect(() => createApp({ modules: [OW], health: true })).toThrow(/^route @Ws \/__ready__ at OwnWs\.ready uses/);
|
||||
|
||||
const off = createApp({ modules: [O] });
|
||||
expect(await (await off.fetch(new Request('http://x/__ready__'))).json()).toEqual({ mine: true });
|
||||
});
|
||||
|
||||
it('a teapot route at /__ready__ fails the teacup splice while health is on', async () => {
|
||||
const wss = new WebSocketServer({ port: 0 });
|
||||
wss.on('connection', (ws) => {
|
||||
ws.on('message', (data) => {
|
||||
if (decode(data.toString()).type === 'hello') {
|
||||
ws.send(
|
||||
encode({
|
||||
type: 'manifest',
|
||||
v: MESH_PROTOCOL_VERSION,
|
||||
steps: [],
|
||||
routes: [{ method: 'GET', pattern: '/__ready__' }],
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
const url = `ws://127.0.0.1:${(wss.address() as AddressInfo).port}/__mesh__/control`;
|
||||
const teacup = createApp({
|
||||
modules: [M],
|
||||
health: true,
|
||||
experimental: true,
|
||||
mesh: { teapots: [{ url, secret: 's' }] },
|
||||
logger: silentLogger(),
|
||||
});
|
||||
|
||||
try {
|
||||
await expect(teacup.ready()).rejects.toThrow(
|
||||
`mesh: remote route 'GET /__ready__' from ${url} uses the reserved path /__ready__`,
|
||||
);
|
||||
} finally {
|
||||
await teacup.close();
|
||||
wss.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/** One request on `agent` (kept alive), resolving with status and body. */
|
||||
function request(port: number, path: string, agent: http.Agent) {
|
||||
return new Promise<{ status: number; body: string }>((resolve, reject) => {
|
||||
const req = http.get({ host: '127.0.0.1', port, path, agent }, (res) => {
|
||||
let body = '';
|
||||
res.on('data', (chunk) => (body += chunk));
|
||||
res.on('end', () => resolve({ status: res.statusCode ?? 0, body }));
|
||||
});
|
||||
req.on('error', reject);
|
||||
});
|
||||
}
|
||||
|
||||
describe('CARD-17: the Node listener', () => {
|
||||
const agents: http.Agent[] = [];
|
||||
|
||||
afterEach(() => agents.splice(0).forEach((agent) => agent.destroy()));
|
||||
|
||||
it('serves the probes before the gate; listen() boots first, so the listener never says booting', async () => {
|
||||
const app = make({ health: true });
|
||||
const server = await app.listen(0);
|
||||
const agent = new http.Agent({ keepAlive: true });
|
||||
agents.push(agent);
|
||||
|
||||
try {
|
||||
const port = (server.address() as AddressInfo).port;
|
||||
expect(await request(port, '/__ready__', agent)).toEqual({ status: 200, body: '{"status":"ok"}' });
|
||||
expect(await request(port, '/__live__', agent)).toEqual({ status: 200, body: '{"status":"ok"}' });
|
||||
} finally {
|
||||
await app.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('T4: close() flips /__ready__ to 503 on a kept-alive connection while a slow request completes', async () => {
|
||||
const app = make({ health: { drainDelayMs: 300 } });
|
||||
const server = await app.listen(0);
|
||||
const port = (server.address() as AddressInfo).port;
|
||||
const agent = new http.Agent({ keepAlive: true, maxSockets: 1 });
|
||||
const slowAgent = new http.Agent({ keepAlive: true });
|
||||
agents.push(agent, slowAgent);
|
||||
|
||||
// Warm the probe connection so the next probe reuses it.
|
||||
expect((await request(port, '/__ready__', agent)).status).toBe(200);
|
||||
const slow = request(port, '/slow', slowAgent);
|
||||
await sleep(20);
|
||||
|
||||
const closing = app.close();
|
||||
const drained = await request(port, '/__ready__', agent);
|
||||
expect(drained).toEqual({ status: 503, body: '{"status":"draining"}' });
|
||||
|
||||
releaseSlow();
|
||||
expect(await slow).toEqual({ status: 200, body: '{"slow":true}' });
|
||||
await closing;
|
||||
});
|
||||
|
||||
it('T4 without drainDelayMs: close() still marks the app draining before it drains', async () => {
|
||||
const app = make({ health: true });
|
||||
await app.listen(0);
|
||||
await app.close();
|
||||
expect((await probe(app, '/__ready__')).body).toEqual({ status: 'draining' });
|
||||
});
|
||||
|
||||
it('the drain window comes out of the close() budget', async () => {
|
||||
const app = make({ health: { drainDelayMs: 200 } });
|
||||
await app.listen(0);
|
||||
const started = Date.now();
|
||||
await app.close({ timeoutMs: 1000 });
|
||||
const took = Date.now() - started;
|
||||
expect(took).toBeGreaterThanOrEqual(190);
|
||||
expect(took).toBeLessThan(1000);
|
||||
});
|
||||
|
||||
it('a POST probe on the listener answers 405 with Allow', async () => {
|
||||
const app = make({ health: true });
|
||||
const server = await app.listen(0);
|
||||
|
||||
try {
|
||||
const port = (server.address() as AddressInfo).port;
|
||||
const res = await new Promise<http.IncomingMessage>((resolve) => {
|
||||
const req = http.request({ host: '127.0.0.1', port, path: '/__ready__', method: 'POST' }, resolve);
|
||||
req.end();
|
||||
});
|
||||
res.resume();
|
||||
expect(res.statusCode).toBe(405);
|
||||
expect(res.headers.allow).toBe('GET, HEAD');
|
||||
expect(res.headers['cache-control']).toBe('no-store');
|
||||
} finally {
|
||||
await app.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user