Skip to content
Source
Sign inSign up
samwillis/one-million-boxes
Open History to see the last commit

realtime-diagnostics.test.ts

31 lines915 Bytes

1import { expect, test } from "vitest"
2import { emptyTile } from "../../../shared/tiles"
3import { boardPayloadSize } from "../../../src/lib/realtime-diagnostics"
4​
5test("counts base64 protocol rows including keys and boundary tile bytes", () => {
6 const rows = [0, 15624].map((tileId) => ({
7 rowId: "a".repeat(64),
8 row: { ...emptyTile(tileId), revision: 123 },
9 }))
10 const wireBytes = rows.reduce(
11 (total, { rowId, row }) =>
12 total +
13 Buffer.byteLength(
14 JSON.stringify({
15 row_key: rowId,
16 values: [
17 String(row.tile_id),
18 String(row.revision),
19 { base64: Buffer.from(row.edges).toString("base64") },
20 { base64: Buffer.from(row.boxes).toString("base64") },
21 ],
22 }),
23 ),
24 0,
25 )
26 expect(boardPayloadSize(rows)).toEqual({
27 rows: 2,
28 packedKB: 0.15,
29 protocolRowsKB: wireBytes / 1000,
30 })
31})