diff --git a/packages/cloudflare-workers/vitest.config.ts b/packages/cloudflare-workers/vitest.config.ts index f30276784..9a4971dc0 100644 --- a/packages/cloudflare-workers/vitest.config.ts +++ b/packages/cloudflare-workers/vitest.config.ts @@ -6,6 +6,6 @@ export default defineConfig({ test: { ...defaultConfig.test, // Requires time for installing packages - testTimeout: 15_000, + testTimeout: 60_000, }, }); diff --git a/packages/rivetkit/src/driver-test-suite/tests/actor-conn-state.ts b/packages/rivetkit/src/driver-test-suite/tests/actor-conn-state.ts index b36665933..0a9c29b76 100644 --- a/packages/rivetkit/src/driver-test-suite/tests/actor-conn-state.ts +++ b/packages/rivetkit/src/driver-test-suite/tests/actor-conn-state.ts @@ -162,20 +162,44 @@ export function runActorConnStateTests(driverTestConfig: DriverTestConfig) { }); // Initial disconnection count - const initialDisconnections = await conn.getDisconnectionCount(); + await vi.waitFor(async () => { + const disconnects = await conn.getDisconnectionCount(); + expect(disconnects).toBe(0); + }); // Dispose the connection await conn.dispose(); + // Validate conn count + await vi.waitFor( + async () => { + const disconnects = await newConn.getDisconnectionCount(); + expect(disconnects).toBe(1); + }, + // SSE takes a long time to disconnect on CF Workers + { + timeout: 10_000, + interval: 100, + }, + ); + // Create a new connection to check the disconnection count const newConn = handle.connect(); + // Verify the connection is tracked + await vi.waitFor(async () => { + const connectionIds = await conn.getConnectionIds(); + expect(connectionIds.length).toBe(2); + }); + + // Clean up + await newConn.dispose(); + // Verify disconnection was tracked await vi.waitFor( async () => { - const newDisconnections = await newConn.getDisconnectionCount(); - - expect(newDisconnections).toBeGreaterThan(initialDisconnections); + const disconnects = await newConn.getDisconnectionCount(); + expect(disconnects).toBe(2); }, // SSE takes a long time to disconnect on CF Workers { @@ -183,9 +207,6 @@ export function runActorConnStateTests(driverTestConfig: DriverTestConfig) { interval: 100, }, ); - - // Clean up - await newConn.dispose(); }); test("should update connection state", async (c) => {