Skip to content

Commit 1781491

Browse files
committed
test(client): per test case timeouts with debug support
- For longer test cases, modify that case's timeout without impacting general timeouts. - Detect when debugger is attached and alter timeouts to increase by x1000
1 parent c4da0c6 commit 1781491

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

packages/service-clients/end-to-end-tests/azure-client/src/test/multiprocess/orchestratorUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const childLoggingVerbosity = process.env.FLUID_TEST_VERBOSE ?? "none";
3333
/**
3434
* Capture console./warn/error before test infrastructure alters it.
3535
*/
36-
const testConsole = {
36+
export const testConsole = {
3737
log: console.log,
3838
warn: console.warn,
3939
error: console.error,

packages/service-clients/end-to-end-tests/azure-client/src/test/multiprocess/presenceTest.spec.ts

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { strict as assert } from "node:assert";
77
import type { ChildProcess } from "node:child_process";
8+
import inspector from "node:inspector";
89

910
import type { AttendeeId } from "@fluidframework/presence/beta";
1011
import { timeoutPromise } from "@fluidframework/test-utils/internal";
@@ -14,13 +15,45 @@ import {
1415
forkChildProcesses,
1516
connectChildProcesses,
1617
connectAndWaitForAttendees,
18+
getLatestMapValueResponses,
19+
getLatestValueResponses,
1720
registerWorkspaceOnChildren,
18-
waitForLatestValueUpdates,
21+
testConsole,
1922
waitForLatestMapValueUpdates,
20-
getLatestValueResponses,
21-
getLatestMapValueResponses,
23+
waitForLatestValueUpdates,
2224
} from "./orchestratorUtils.js";
2325

26+
const debuggerAttached = inspector.url() !== undefined;
27+
28+
/**
29+
* Set this to a high number when debugging to avoid timeouts from debugging time.
30+
*/
31+
const timeoutMultiplier = debuggerAttached ? 1000 : 1;
32+
33+
/**
34+
* Sets the timeout for the given test context.
35+
*
36+
* @remarks
37+
* If a debugger is attached, the timeout is set to 0 to prevent timeouts during debugging.
38+
* Otherwise, it sets the timeout to the maximum of the current timeout and the specified duration.
39+
*
40+
* @param context - The Mocha test context.
41+
* @param duration - The duration in milliseconds to set the timeout to. Zero disables the timeout.
42+
*/
43+
function setTimeout(context: Mocha.Context, duration: number): void {
44+
const currentTimeout = context.timeout();
45+
const newTimeout =
46+
debuggerAttached || currentTimeout === 0 || duration === 0
47+
? 0
48+
: Math.max(currentTimeout, duration);
49+
if (newTimeout !== currentTimeout) {
50+
testConsole.log(
51+
`${context.test?.title}: setting timeout to ${newTimeout}ms (was ${currentTimeout}ms)`,
52+
);
53+
context.timeout(newTimeout);
54+
}
55+
}
56+
2457
/**
2558
* This test suite is a prototype for a multi-process end to end test for Fluid using the new Presence API on AzureClient.
2659
* In the future we hope to expand and generalize this pattern to broadly test more Fluid features.
@@ -71,11 +104,11 @@ describe(`Presence with AzureClient`, () => {
71104
/**
72105
* Timeout for child processes to connect to container ({@link ConnectedEvent})
73106
*/
74-
const childConnectTimeoutMs = 1000 * numClients;
107+
const childConnectTimeoutMs = 1000 * numClients * timeoutMultiplier;
75108
/**
76109
* Timeout for presence attendees to connect {@link AttendeeConnectedEvent}
77110
*/
78-
const attendeesJoinedTimeoutMs = 2000;
111+
const attendeesJoinedTimeoutMs = (1000 + 200 * numClients) * timeoutMultiplier;
79112
/**
80113
* Timeout for workspace registration {@link WorkspaceRegisteredEvent}
81114
*/
@@ -90,7 +123,9 @@ describe(`Presence with AzureClient`, () => {
90123
const getStateTimeoutMs = 5000;
91124

92125
for (const writeClients of [numClients, 1]) {
93-
it(`announces 'attendeeConnected' when remote client joins session [${numClients} clients, ${writeClients} writers]`, async () => {
126+
it(`announces 'attendeeConnected' when remote client joins session [${numClients} clients, ${writeClients} writers]`, async function () {
127+
setTimeout(this, childConnectTimeoutMs + attendeesJoinedTimeoutMs + 1000);
128+
94129
// Setup
95130
const { children, childErrorPromise } = await forkChildProcesses(
96131
numClients,
@@ -118,6 +153,13 @@ describe(`Presence with AzureClient`, () => {
118153
this.skip();
119154
}
120155

156+
const childDisconnectTimeoutMs = 10_000 * timeoutMultiplier;
157+
158+
setTimeout(
159+
this,
160+
childConnectTimeoutMs + attendeesJoinedTimeoutMs + childDisconnectTimeoutMs + 1000,
161+
);
162+
121163
// Setup
122164
const { children, childErrorPromise } = await forkChildProcesses(
123165
numClients,
@@ -135,8 +177,6 @@ describe(`Presence with AzureClient`, () => {
135177
childErrorPromise,
136178
);
137179

138-
const childDisconnectTimeoutMs = 10_000;
139-
140180
const waitForDisconnected = children.map(async (child, index) =>
141181
index === 0
142182
? Promise.resolve()

0 commit comments

Comments
 (0)