Skip to content

Commit 518db1e

Browse files
Copilotkobenguyent
andcommitted
Improve TestCafe form submission timeout handling with polling mechanism
Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
1 parent bba8bd4 commit 518db1e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/utils.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,21 @@ module.exports.test = {
192192
return function (key) {
193193
if (!fs.existsSync(dataFile)) {
194194
// Increase wait time for CI environments where form submission may be slower
195-
const waitTime = process.env.CI ? 10 * 1000 : 1 * 1000 // 10 seconds in CI, 1 second otherwise
196-
const waitTill = new Date(new Date().getTime() + waitTime)
197-
while (waitTill > new Date()) {}
195+
const waitTime = process.env.CI ? 15 * 1000 : 1 * 1000 // 15 seconds in CI, 1 second otherwise
196+
const pollInterval = 100 // Check every 100ms
197+
const startTime = new Date().getTime()
198+
199+
// Poll for file existence instead of busy waiting
200+
while (new Date().getTime() - startTime < waitTime) {
201+
if (fs.existsSync(dataFile)) {
202+
break
203+
}
204+
// Sleep for pollInterval milliseconds
205+
const start = new Date().getTime()
206+
while (new Date().getTime() - start < pollInterval) {
207+
// Small busy wait for polling interval
208+
}
209+
}
198210
}
199211
if (!fs.existsSync(dataFile)) {
200212
throw new Error('Data file was not created in time')

0 commit comments

Comments
 (0)