forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-events.test.ts
More file actions
42 lines (33 loc) · 1.26 KB
/
Copy pathruntime-events.test.ts
File metadata and controls
42 lines (33 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { describe, it, expect, vi } from "vitest";
import { RuntimeEventBus } from "../runtime-events.js";
describe("RuntimeEventBus max listeners", () => {
it("warns when exceeding maxListenersPerEvent", () => {
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
const bus = new RuntimeEventBus(2);
bus.on("runtime.started", () => {});
bus.on("runtime.started", () => {});
bus.on("runtime.started", () => {});
expect(warnSpy).toHaveBeenCalledTimes(1);
expect(warnSpy.mock.calls[0]![0]).toContain(
"max listener count (2) exceeded"
);
warnSpy.mockRestore();
});
it("exposes listenerCount", () => {
const bus = new RuntimeEventBus();
expect(bus.listenerCount("runtime.started")).toBe(0);
const unsub = bus.on("runtime.started", () => {});
expect(bus.listenerCount("runtime.started")).toBe(1);
unsub();
expect(bus.listenerCount("runtime.started")).toBe(0);
});
it("defaults to 100 max listeners", () => {
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
const bus = new RuntimeEventBus();
for (let i = 0; i < 101; i++) {
bus.on("runtime.started", () => {});
}
expect(warnSpy).toHaveBeenCalledTimes(1);
warnSpy.mockRestore();
});
});