Adds a per-subsystem measurement of reactive.js, made by minifying it repeatedly with one subsystem removed rather than counting source bytes. This corrects the earlier audit on both figures and on the conclusion drawn from them. Component controllers are 23,722 bytes minified / 6,660 gzipped -- 30.6% of transfer, not the "about 18%" previously claimed -- and splitting them out saves 6.6 kB gzipped on a typical page, not "3-4 kB". Measured against the example app, / and /login use none of the ten controllers and /layout uses one, so most pages download and parse the lot for nothing. The larger finding is that the runtime is not where the weight is. One page parses 490,212 decoded bytes across 11 generated client modules while transferring 21,026, and the largest module is 89.8% duplicated lines: the state-restore prologue appears 162 times because client-codegen.ts inlines the sync into every peer alias of every client function. Gzip hides it on the wire, but parse cost follows decoded bytes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import {
|
|
RPC_ERROR_CODES,
|
|
failure,
|
|
retryingTransport,
|
|
success,
|
|
type Transport,
|
|
} from "../src/index.ts";
|
|
|
|
function failingTransport(): { transport: Transport; calls: () => number } {
|
|
let count = 0;
|
|
return {
|
|
transport: {
|
|
async call() {
|
|
count++;
|
|
return failure(RPC_ERROR_CODES.transport, "down");
|
|
},
|
|
},
|
|
calls: () => count,
|
|
};
|
|
}
|
|
|
|
describe("retryingTransport", () => {
|
|
test("retries only declared idempotent calls", async () => {
|
|
const retryable = failingTransport();
|
|
const write = failingTransport();
|
|
const options = { retries: 2, backoffMs: 0 };
|
|
await retryingTransport(retryable.transport, options).call(
|
|
{ app: "billing", service: "invoice", procedure: "get" },
|
|
{},
|
|
{ idempotent: true },
|
|
);
|
|
await retryingTransport(write.transport, options).call(
|
|
{ app: "billing", service: "invoice", procedure: "create" },
|
|
{},
|
|
{ idempotent: false },
|
|
);
|
|
expect(retryable.calls()).toBe(3);
|
|
expect(write.calls()).toBe(1);
|
|
});
|
|
|
|
test("opens a circuit after repeated exhausted failures and recovers after cooldown", async () => {
|
|
let clock = 0;
|
|
let calls = 0;
|
|
const base: Transport = {
|
|
async call() {
|
|
calls++;
|
|
return calls < 3 ? failure(RPC_ERROR_CODES.transport, "down") : success("ok");
|
|
},
|
|
};
|
|
const transport = retryingTransport(base, {
|
|
retries: 0,
|
|
circuitFailureThreshold: 2,
|
|
circuitCooldownMs: 10,
|
|
now: () => clock,
|
|
});
|
|
const target = { app: "billing", service: "invoice", procedure: "get" };
|
|
await transport.call(target, {}, { idempotent: true });
|
|
await transport.call(target, {}, { idempotent: true });
|
|
expect(await transport.call(target, {}, { idempotent: true })).toMatchObject({
|
|
ok: false,
|
|
code: RPC_ERROR_CODES.transport,
|
|
});
|
|
expect(calls).toBe(2);
|
|
clock = 11;
|
|
expect(await transport.call(target, {}, { idempotent: true })).toEqual(success("ok"));
|
|
});
|
|
});
|