mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-04 22:32:12 +03:00
test(perf): add performance instrumentation tests
This commit is contained in:
@@ -7,9 +7,8 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
const { assembleStreamingPipeline } = await import(
|
||||
"../../open-sse/handlers/chatCore/streamingPipeline.ts"
|
||||
);
|
||||
const { assembleStreamingPipeline } =
|
||||
await import("../../open-sse/handlers/chatCore/streamingPipeline.ts");
|
||||
|
||||
// A fake stream: each pipeThrough appends the transform's tag and returns a new fake stream.
|
||||
function fakeStream(tag: string, log: string[]) {
|
||||
@@ -100,3 +99,37 @@ test("full chain order: pii → progress → heartbeat → echo", () => {
|
||||
assembleStreamingPipeline(baseArgs({ echoModel: "alias-x" }), deps);
|
||||
assert.deepEqual(log, ["pii-flag", "progress", "heartbeat", "echo"]);
|
||||
});
|
||||
|
||||
test("pipeline assembly creates performance mark and measure entries", () => {
|
||||
performance.clearMarks();
|
||||
performance.clearMeasures();
|
||||
const { deps } = makeDeps();
|
||||
assembleStreamingPipeline(baseArgs(), deps);
|
||||
assert.equal(performance.getEntriesByName("omni-pipeline-start").length, 1, "start mark");
|
||||
assert.equal(performance.getEntriesByName("omni-pipeline-end").length, 1, "end mark");
|
||||
assert.equal(performance.getEntriesByName("omni-pipeline").length, 1, "measure");
|
||||
});
|
||||
|
||||
test("re-entering pipeline clears previous timeline entries", () => {
|
||||
performance.clearMarks();
|
||||
performance.clearMeasures();
|
||||
const { deps } = makeDeps();
|
||||
// First call creates entries
|
||||
assembleStreamingPipeline(baseArgs(), deps);
|
||||
// Second call — clearMarks/clearMeasures runs before new marks, so count stays 1
|
||||
assembleStreamingPipeline(baseArgs(), deps);
|
||||
assert.equal(performance.getEntriesByName("omni-pipeline-start").length, 1, "start cleared");
|
||||
assert.equal(performance.getEntriesByName("omni-pipeline-end").length, 1, "end cleared");
|
||||
assert.equal(performance.getEntriesByName("omni-pipeline").length, 1, "measure cleared");
|
||||
});
|
||||
|
||||
test("performance measure has positive duration", () => {
|
||||
performance.clearMarks();
|
||||
performance.clearMeasures();
|
||||
const { deps } = makeDeps();
|
||||
assembleStreamingPipeline(baseArgs(), deps);
|
||||
const [entry] = performance.getEntriesByName("omni-pipeline");
|
||||
assert.ok(entry, "measure exists");
|
||||
assert.equal(entry.entryType, "measure");
|
||||
assert.ok(entry.duration >= 0, `duration ${entry.duration} >= 0`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user