@@ -17,7 +17,7 @@ import { createRuntimeChannel } from "../plugins/runtime/runtime-channel.js";
|
17 | 17 | import type { PluginRuntime } from "../plugins/runtime/types.js"; |
18 | 18 | import { DEFAULT_ACCOUNT_ID } from "../routing/session-key.js"; |
19 | 19 | import type { RuntimeEnv } from "../runtime.js"; |
20 | | -import { createChannelManager } from "./server-channels.js"; |
| 20 | +import { createChannelManager, type ChannelManager } from "./server-channels.js"; |
21 | 21 | |
22 | 22 | const hoisted = vi.hoisted(() => { |
23 | 23 | const computeBackoff = vi.fn(() => 10); |
@@ -47,6 +47,8 @@ type TestAccount = {
|
47 | 47 | configured?: boolean; |
48 | 48 | }; |
49 | 49 | |
| 50 | +const createdManagers: Array<{ manager: ChannelManager; channelIds: ChannelId[] }> = []; |
| 51 | + |
50 | 52 | function createTestPlugin(params?: { |
51 | 53 | id?: ChannelId; |
52 | 54 | order?: number; |
@@ -172,7 +174,7 @@ function createManager(options?: {
|
172 | 174 | channelRuntimeEnvs[channelId] ??= runtime; |
173 | 175 | } |
174 | 176 | } |
175 | | -return createChannelManager({ |
| 177 | +const manager = createChannelManager({ |
176 | 178 | getRuntimeConfig: () => options?.getRuntimeConfig?.() ?? {}, |
177 | 179 | channelLogs, |
178 | 180 | channelRuntimeEnvs, |
@@ -185,6 +187,8 @@ function createManager(options?: {
|
185 | 187 | : {}), |
186 | 188 | ...(options?.startupTrace ? { startupTrace: options.startupTrace } : {}), |
187 | 189 | }); |
| 190 | +createdManagers.push({ channelIds, manager }); |
| 191 | +return manager; |
188 | 192 | } |
189 | 193 | |
190 | 194 | describe("server-channels auto restart", () => { |
@@ -197,7 +201,15 @@ describe("server-channels auto restart", () => {
|
197 | 201 | hoisted.sleepWithAbort.mockClear(); |
198 | 202 | }); |
199 | 203 | |
200 | | -afterEach(() => { |
| 204 | +afterEach(async () => { |
| 205 | +const stops = createdManagers |
| 206 | +.splice(0) |
| 207 | +.flatMap(({ channelIds, manager }) => |
| 208 | +channelIds.map((channelId) => manager.stopChannel(channelId).catch(() => {})), |
| 209 | +); |
| 210 | +await vi.advanceTimersByTimeAsync(6_000); |
| 211 | +await Promise.allSettled(stops); |
| 212 | +await flushMicrotasks(); |
201 | 213 | vi.clearAllTimers(); |
202 | 214 | vi.useRealTimers(); |
203 | 215 | setActivePluginRegistry(previousRegistry ?? createEmptyPluginRegistry()); |
|