mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:30:42 +00:00
test: clean up voice-call event timers
This commit is contained in:
@@ -1,17 +1,32 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { VoiceCallConfigSchema } from "../config.js";
|
||||
import type { VoiceCallProvider } from "../providers/base.js";
|
||||
import type { HangupCallInput, NormalizedEvent } from "../types.js";
|
||||
import type { CallManagerContext } from "./context.js";
|
||||
import { processEvent } from "./events.js";
|
||||
|
||||
const contexts: CallManagerContext[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
for (const ctx of contexts.splice(0)) {
|
||||
for (const timer of ctx.maxDurationTimers.values()) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
ctx.maxDurationTimers.clear();
|
||||
for (const waiter of ctx.transcriptWaiters.values()) {
|
||||
clearTimeout(waiter.timeout);
|
||||
}
|
||||
ctx.transcriptWaiters.clear();
|
||||
fs.rmSync(ctx.storePath, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
function createContext(overrides: Partial<CallManagerContext> = {}): CallManagerContext {
|
||||
const storePath = path.join(os.tmpdir(), `openclaw-voice-call-events-test-${Date.now()}`);
|
||||
fs.mkdirSync(storePath, { recursive: true });
|
||||
return {
|
||||
const storePath = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-voice-call-events-test-"));
|
||||
const ctx: CallManagerContext = {
|
||||
activeCalls: new Map(),
|
||||
providerCallIdMap: new Map(),
|
||||
processedEventIds: new Set(),
|
||||
@@ -30,6 +45,8 @@ function createContext(overrides: Partial<CallManagerContext> = {}): CallManager
|
||||
initialMessageInFlight: new Set(),
|
||||
...overrides,
|
||||
};
|
||||
contexts.push(ctx);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
function createProvider(overrides: Partial<VoiceCallProvider> = {}): VoiceCallProvider {
|
||||
|
||||
Reference in New Issue
Block a user