release: WRNexusJS 0.4.0
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { test, expect } from "bun:test";
|
||||
import { createContext } from "@wrnexus/core";
|
||||
import { createTracker, type ErrorEvent, type ErrorSink } from "../src/index.ts";
|
||||
import {
|
||||
createTelemetryPipeline,
|
||||
createTracker,
|
||||
type ErrorEvent,
|
||||
type ErrorSink,
|
||||
} from "../src/index.ts";
|
||||
|
||||
function collectingSink(): ErrorSink & { events: ErrorEvent[] } {
|
||||
const events: ErrorEvent[] = [];
|
||||
@@ -59,3 +64,34 @@ test("a failing sink never breaks capture", async () => {
|
||||
await tracker.capture(new Error("x")); // must not throw
|
||||
expect(good.events.length).toBe(1);
|
||||
});
|
||||
|
||||
test("telemetry requeues a failed batch only once when multiple sinks fail", async () => {
|
||||
let failures = 0;
|
||||
const pipeline = createTelemetryPipeline({
|
||||
batchSize: 2,
|
||||
flushIntervalMs: 0,
|
||||
sinks: [
|
||||
{
|
||||
send: () => {
|
||||
throw new Error("one");
|
||||
},
|
||||
},
|
||||
{
|
||||
send: () => {
|
||||
throw new Error("two");
|
||||
},
|
||||
},
|
||||
],
|
||||
onSinkError: () => {
|
||||
failures++;
|
||||
},
|
||||
});
|
||||
|
||||
await pipeline.emit({ kind: "event", name: "one", attributes: {} });
|
||||
await pipeline.emit({ kind: "event", name: "two", attributes: {} });
|
||||
|
||||
expect(failures).toBe(2);
|
||||
expect(pipeline.size()).toBe(2);
|
||||
await pipeline.close();
|
||||
expect(pipeline.size()).toBe(2);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user