Skip to content
Source
Sign inSign up

ZlibProbe.e2e.test.ts

82 lines2.7 KB

1import * as Cloudflare from "@alchemy.run/cloudflare";
2import { expect } from "@alchemy.run/test";
3import * as Test from "@alchemy.run/test/Alchemy";
4/**
5 * The same probe as ZlibProbe.local.test.ts, against REAL Cloudflare: which
6 * synchronous exact-span inflate paths exist in production workerd, and
7 * what each costs per entry (client-measured wall time over 2,000 entries).
8 * DESIGN §22.4: this is what decides the push-ingest CPU story.
9 */
10import * as Alchemy from "alchemy";
11import * as Effect from "effect/Effect";
12import * as HttpClient from "effect/http/HttpClient";
13import * as Schedule from "effect/Schedule";
14import ZlibProbeWorker from "./fixtures/zlib-probe-worker.ts";
15​
16const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
17 providers: Cloudflare.providers(),
18});
19​
20const Stack = Alchemy.Stack(
21 "ZlibProbeCloudStack",
22 { providers: Cloudflare.providers(), state: Cloudflare.state() },
23 Effect.gen(function* () {
24 const worker = yield* ZlibProbeWorker;
25 return { url: worker.url.as<string>() };
26 }),
27);
28​
29const stack = beforeAll(deploy(Stack));
30afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack));
31​
32test(
33 "production workerd: which exact-span inflate paths work, and their cost",
34 Effect.gen(function* () {
35 const { url } = yield* stack;
36 const client = yield* HttpClient.HttpClient;
37 const get = (q: string) =>
38 client.get(`${url}/?${q}`).pipe(
39 Effect.flatMap((res) =>
40 res.status === 200 ? res.json : Effect.fail(new Error(`status ${res.status}`)),
41 ),
42 Effect.retry({
43 schedule: Schedule.exponential("500 millis"),
44 times: 10,
45 }),
46 );
47 const probe = (yield* get("path=probe")) as Record<string, unknown>;
48 console.log("[zlib-cloud] probe", JSON.stringify(probe));
49 const N = 2000;
50 const nFor = (path: string) => (path.startsWith("deflate") ? 200 : N);
51 for (const path of [
52 "processChunk",
53 "processChunkReuse",
54 "info",
55 "plain",
56 "stream",
57 "sha1",
58 "copy",
59 "jsloop",
60 "effect",
61 "deflate6",
62 "deflate1",
63 ]) {
64 yield* get(`path=${path}&n=50`); // warm
65 const t0 = performance.now();
66 const n = nFor(path);
67 const r = (yield* get(`path=${path}&n=${n}`)) as {
68 ok: number;
69 error?: string;
70 };
71 const ms = performance.now() - t0;
72 console.log(
73 `[zlib-cloud] ${path.padEnd(12)} ok ${r.ok}/${n} in ${ms.toFixed(0)}ms → ${(ms / n).toFixed(3)} ms/entry${r.error ? ` error: ${r.error}` : ""}`,
74 );
75 }
76 expect(probe).toBeDefined();
77 }),
78 {
79 tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"],
80 timeout: 300_000,
81 },
82);