testdriverai 7.2.85 → 7.2.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent/lib/redraw.js +33 -26
- package/package.json +1 -1
package/agent/lib/redraw.js
CHANGED
|
@@ -21,7 +21,8 @@ const createRedraw = (
|
|
|
21
21
|
// Merge default options with provided defaults
|
|
22
22
|
const baseOptions = { ...DEFAULT_REDRAW_OPTIONS, ...defaultOptions };
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
// Network check interval (ms) - used for speed calculation display
|
|
25
|
+
const networkCheckInterval = 250;
|
|
25
26
|
|
|
26
27
|
let lastTxBytes = null;
|
|
27
28
|
let lastRxBytes = null;
|
|
@@ -125,15 +126,32 @@ const createRedraw = (
|
|
|
125
126
|
}
|
|
126
127
|
};
|
|
127
128
|
|
|
129
|
+
// Track if a network request is in flight to prevent overlapping requests
|
|
130
|
+
let networkRequestInFlight = false;
|
|
131
|
+
|
|
128
132
|
async function updateNetwork() {
|
|
133
|
+
// Prevent overlapping requests - if one is already in flight, skip this cycle
|
|
134
|
+
if (networkRequestInFlight) {
|
|
135
|
+
emitter.emit(events.log.debug, '[redraw] updateNetwork() - skipping, request already in flight');
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
129
139
|
if (sandbox && sandbox.instanceSocketConnected) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
network
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
networkRequestInFlight = true;
|
|
141
|
+
try {
|
|
142
|
+
let network = await sandbox.send({
|
|
143
|
+
type: "system.network",
|
|
144
|
+
}, 10000); // Use a shorter 10 second timeout for network stats
|
|
145
|
+
parseNetworkStats(
|
|
146
|
+
network.out.totalBytesReceived,
|
|
147
|
+
network.out.totalBytesSent,
|
|
148
|
+
);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
// Log the error but don't throw - network monitoring is non-critical
|
|
151
|
+
emitter.emit(events.log.debug, `[redraw] updateNetwork() failed: ${error.message}`);
|
|
152
|
+
} finally {
|
|
153
|
+
networkRequestInFlight = false;
|
|
154
|
+
}
|
|
137
155
|
}
|
|
138
156
|
}
|
|
139
157
|
|
|
@@ -181,14 +199,7 @@ const createRedraw = (
|
|
|
181
199
|
}
|
|
182
200
|
}
|
|
183
201
|
|
|
184
|
-
//
|
|
185
|
-
function startNetworkMonitoring() {
|
|
186
|
-
if (!networkInterval) {
|
|
187
|
-
networkInterval = setInterval(updateNetwork, networkUpdateInterval);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Stop network monitoring
|
|
202
|
+
// Stop network monitoring (cleanup any residual interval)
|
|
192
203
|
function stopNetworkMonitoring() {
|
|
193
204
|
if (networkInterval) {
|
|
194
205
|
clearInterval(networkInterval);
|
|
@@ -220,11 +231,6 @@ const createRedraw = (
|
|
|
220
231
|
|
|
221
232
|
resetState();
|
|
222
233
|
|
|
223
|
-
// Only start network monitoring if enabled
|
|
224
|
-
if (currentOptions.networkMonitor) {
|
|
225
|
-
startNetworkMonitoring();
|
|
226
|
-
}
|
|
227
|
-
|
|
228
234
|
// Capture initial image for screen stability monitoring
|
|
229
235
|
if (currentOptions.screenRedraw) {
|
|
230
236
|
initialScreenImage = await system.captureScreenPNG(0.25, true);
|
|
@@ -244,6 +250,11 @@ const createRedraw = (
|
|
|
244
250
|
return;
|
|
245
251
|
}
|
|
246
252
|
|
|
253
|
+
// Update network stats on each check (with guard against overlapping requests)
|
|
254
|
+
if (networkMonitor) {
|
|
255
|
+
await updateNetwork();
|
|
256
|
+
}
|
|
257
|
+
|
|
247
258
|
let nowImage = screenRedraw ? await system.captureScreenPNG(0.25, true) : null;
|
|
248
259
|
let timeElapsed = Date.now() - startTime;
|
|
249
260
|
let diffFromInitial = 0;
|
|
@@ -305,7 +316,7 @@ const createRedraw = (
|
|
|
305
316
|
: effectiveNetworkSettled
|
|
306
317
|
? theme.green(`y`)
|
|
307
318
|
: theme.dim(
|
|
308
|
-
`${Math.trunc((diffRxBytes + diffTxBytes) /
|
|
319
|
+
`${Math.trunc((diffRxBytes + diffTxBytes) / (networkCheckInterval / 1000))}b/s`,
|
|
309
320
|
);
|
|
310
321
|
let timeoutText = isTimeout
|
|
311
322
|
? theme.green(`y`)
|
|
@@ -370,10 +381,6 @@ const createRedraw = (
|
|
|
370
381
|
|
|
371
382
|
return new Promise((resolve) => {
|
|
372
383
|
const startTime = Date.now();
|
|
373
|
-
// Start network monitoring if not already started and enabled
|
|
374
|
-
if (waitOptions.networkMonitor) {
|
|
375
|
-
startNetworkMonitoring();
|
|
376
|
-
}
|
|
377
384
|
checkCondition(resolve, startTime, timeoutMs, waitOptions);
|
|
378
385
|
});
|
|
379
386
|
}
|