test(runtimes): close the 1c exit-gate cells for health and compression on Deno and Bun
The CARD-22 gate audit found these runtime cells without tests: - CARD-17 T1-T3 (booting, ok, degraded) existed only on Node. Add them on Deno and Bun. T1 goes through app.fetch, because serveDeno and serveBun boot before they bind. T2 and T3 go through a real listener and assert the response body, not only the status. - CARD-16 T6 (encodings ['gzip'] with a br-only client gives identity) was missing on Deno and Bun. - CARD-16 T8 on Deno and Bun lacked the handler-set content-encoding case and the 204 case. A negative run of T6 against compression: true fails with 'encoded as br', so the check can tell the two cases apart. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
6 files changed
+221
-5
No files matched your search
@@ -5,7 +5,7 @@
|
||||
import 'npm:reflect-metadata';
|
||||
import { serveDeno } from '../../src/deno.ts';
|
||||
import { compressionApp } from '../fixtures/compression-app.ts';
|
||||
import { checks, serverDoesNotCompress, ticksDuringGzip } from '../fixtures/compression-checks.ts';
|
||||
import { checks, gzipOnlyRefusesBr, serverDoesNotCompress, ticksDuringGzip } from '../fixtures/compression-checks.ts';
|
||||
|
||||
for (const [name, run] of Object.entries(checks)) {
|
||||
Deno.test(`compression on Deno.serve: ${name}`, async () => {
|
||||
@@ -23,6 +23,20 @@ for (const [name, run] of Object.entries(checks)) {
|
||||
});
|
||||
}
|
||||
|
||||
Deno.test("compression on Deno.serve: T6 encodings ['gzip'] and a br-only client → identity", async () => {
|
||||
const server = await serveDeno(compressionApp({ compression: { encodings: ['gzip'] } }), {
|
||||
hostname: '127.0.0.1',
|
||||
port: 0,
|
||||
onListen: () => {},
|
||||
});
|
||||
|
||||
try {
|
||||
await gzipOnlyRefusesBr((server as unknown as { addr: { port: number } }).addr.port);
|
||||
} finally {
|
||||
await server.close({ timeoutMs: 1000 });
|
||||
}
|
||||
});
|
||||
|
||||
// The documented Deno facts (CARD-16; `guides/runtimes.md`). If one of these starts failing, Deno
|
||||
// changed and the docs have to change with it — not the assertion.
|
||||
Deno.test('documented: Deno.serve does not compress by itself (core compression off → identity)', async () => {
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
// CARD-17 T1–T3 on Deno: the probe states a load balancer reads. T1 goes through `app.fetch`, because
|
||||
// `serveDeno` boots before it binds and so never answers while booting; T2 and T3 go through a real
|
||||
// `serveDeno` listener. T5 (the drain window) lives in `shutdown.test.ts`.
|
||||
//
|
||||
// Run with: npm run test:deno
|
||||
import 'reflect-metadata';
|
||||
import { createApp, Route, Get, Module, Provider } from '../../src/index.ts';
|
||||
import { serveDeno } from '../../src/deno.ts';
|
||||
|
||||
@Route('/')
|
||||
class Ctl {
|
||||
@Get('/ping')
|
||||
ping() {
|
||||
return { ok: true };
|
||||
}
|
||||
}
|
||||
|
||||
const quiet = { debug() {}, info() {}, warn() {}, error() {} };
|
||||
|
||||
async function expectProbe(res: Response, status: number, body: unknown): Promise<void> {
|
||||
const got = await res.json();
|
||||
if (res.status !== status || JSON.stringify(got) !== JSON.stringify(body)) {
|
||||
throw new Error(`expected ${status} ${JSON.stringify(body)}, got ${res.status} ${JSON.stringify(got)}`);
|
||||
}
|
||||
}
|
||||
|
||||
Deno.test('CARD-17 T1: /__ready__ 503 booting while a slow provider boots, /__live__ 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: quiet });
|
||||
const booting = app.boot();
|
||||
await new Promise((r) => setTimeout(r, 10));
|
||||
|
||||
await expectProbe(await app.fetch(new Request('http://x/__ready__')), 503, { status: 'booting' });
|
||||
await expectProbe(await app.fetch(new Request('http://x/__live__')), 200, { status: 'ok' });
|
||||
|
||||
finish();
|
||||
await booting;
|
||||
await expectProbe(await app.fetch(new Request('http://x/__ready__')), 200, { status: 'ok' });
|
||||
});
|
||||
|
||||
Deno.test('CARD-17 T2: serveDeno, booted with nothing degraded → 200 ok', async () => {
|
||||
@Module({ mountpoint: '/', controllers: [Ctl] })
|
||||
class M {}
|
||||
const server = await serveDeno(createApp({ modules: [M], health: true, logger: quiet }), {
|
||||
port: 0,
|
||||
onListen: () => {},
|
||||
});
|
||||
try {
|
||||
const base = `http://127.0.0.1:${(server as unknown as { addr: { port: number } }).addr.port}`;
|
||||
await expectProbe(await fetch(`${base}/__ready__`), 200, { status: 'ok' });
|
||||
await expectProbe(await fetch(`${base}/__live__`), 200, { status: 'ok' });
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test('CARD-17 T3: serveDeno, 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 server = await serveDeno(createApp({ modules: [D], health: true, logger: quiet }), {
|
||||
port: 0,
|
||||
onListen: () => {},
|
||||
});
|
||||
try {
|
||||
const base = `http://127.0.0.1:${(server as unknown as { addr: { port: number } }).addr.port}`;
|
||||
await expectProbe(await fetch(`${base}/__ready__`), 200, { status: 'degraded', degraded: ['x'] });
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user