5
5
6
6
import { strict as assert } from "node:assert" ;
7
7
import type { ChildProcess } from "node:child_process" ;
8
+ import inspector from "node:inspector" ;
8
9
9
10
import type { AttendeeId } from "@fluidframework/presence/beta" ;
10
11
import { timeoutPromise } from "@fluidframework/test-utils/internal" ;
@@ -14,13 +15,45 @@ import {
14
15
forkChildProcesses ,
15
16
connectChildProcesses ,
16
17
connectAndWaitForAttendees ,
18
+ getLatestMapValueResponses ,
19
+ getLatestValueResponses ,
17
20
registerWorkspaceOnChildren ,
18
- waitForLatestValueUpdates ,
21
+ testConsole ,
19
22
waitForLatestMapValueUpdates ,
20
- getLatestValueResponses ,
21
- getLatestMapValueResponses ,
23
+ waitForLatestValueUpdates ,
22
24
} from "./orchestratorUtils.js" ;
23
25
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
+
24
57
/**
25
58
* This test suite is a prototype for a multi-process end to end test for Fluid using the new Presence API on AzureClient.
26
59
* 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`, () => {
71
104
/**
72
105
* Timeout for child processes to connect to container ({@link ConnectedEvent})
73
106
*/
74
- const childConnectTimeoutMs = 1000 * numClients ;
107
+ const childConnectTimeoutMs = 1000 * numClients * timeoutMultiplier ;
75
108
/**
76
109
* Timeout for presence attendees to connect {@link AttendeeConnectedEvent}
77
110
*/
78
- const attendeesJoinedTimeoutMs = 2000 ;
111
+ const attendeesJoinedTimeoutMs = ( 1000 + 200 * numClients ) * timeoutMultiplier ;
79
112
/**
80
113
* Timeout for workspace registration {@link WorkspaceRegisteredEvent}
81
114
*/
@@ -90,7 +123,9 @@ describe(`Presence with AzureClient`, () => {
90
123
const getStateTimeoutMs = 5000 ;
91
124
92
125
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
+
94
129
// Setup
95
130
const { children, childErrorPromise } = await forkChildProcesses (
96
131
numClients ,
@@ -118,6 +153,13 @@ describe(`Presence with AzureClient`, () => {
118
153
this . skip ( ) ;
119
154
}
120
155
156
+ const childDisconnectTimeoutMs = 10_000 * timeoutMultiplier ;
157
+
158
+ setTimeout (
159
+ this ,
160
+ childConnectTimeoutMs + attendeesJoinedTimeoutMs + childDisconnectTimeoutMs + 1000 ,
161
+ ) ;
162
+
121
163
// Setup
122
164
const { children, childErrorPromise } = await forkChildProcesses (
123
165
numClients ,
@@ -135,8 +177,6 @@ describe(`Presence with AzureClient`, () => {
135
177
childErrorPromise ,
136
178
) ;
137
179
138
- const childDisconnectTimeoutMs = 10_000 ;
139
-
140
180
const waitForDisconnected = children . map ( async ( child , index ) =>
141
181
index === 0
142
182
? Promise . resolve ( )
0 commit comments