Skip to content

Commit

Permalink
tests(core): stats reporting
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Ricart <[email protected]>
  • Loading branch information
aricart committed Oct 16, 2024
1 parent ddbc6bf commit 760d3d2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
41 changes: 41 additions & 0 deletions core/tests/basics_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,47 @@ Deno.test("basics - resolve false", async () => {
await nci.close();
});

Deno.test("basics - stats", async () => {
const { ns, nc } = await _setup(connect);

const cid = nc.info?.client_id || -1;
if (cid === -1) {
fail("client_id not found");
}

async function check(m = ""): Promise<void> {
await nc.flush();
const client = nc.stats();
const { in_msgs, out_msgs, in_bytes, out_bytes } =
(await ns.connz(cid, "detail")).connections[0];
const server = { in_msgs, out_msgs, in_bytes, out_bytes };

console.log(m, client, server);

assertEquals(client.outBytes, in_bytes);
assertEquals(client.inBytes, out_bytes);
assertEquals(client.outMsgs, in_msgs);
assertEquals(client.inMsgs, out_msgs);
}

await check("start");

// publish
nc.publish("hello", "world");
await check("simple publish");

nc.subscribe("hello", { callback: () => {} });
nc.publish("hello", "hi");
await check("subscribe");

const h = headers();
h.set("hello", "very long value that we want to add here");
nc.publish("hello", "hello", { headers: h });
await check("headers");

await cleanup(ns, nc);
});

class MM implements Msg {
data!: Uint8Array;
sid: number;
Expand Down
2 changes: 2 additions & 0 deletions test_helpers/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export interface Conn {
"pending_bytes": number;
"in_msgs": number;
"out_msgs": number;
"in_bytes": number;
"out_bytes": number;
subscriptions: number;
name: string;
lang: string;
Expand Down

0 comments on commit 760d3d2

Please sign in to comment.