@@ -193,21 +193,39 @@ module.exports.test = {
193
193
return function ( key ) {
194
194
if ( ! fs . existsSync ( dataFile ) ) {
195
195
// Increase wait time for CI environments where form submission may be slower
196
- const waitTime = process . env . CI ? 30 * 1000 : 1 * 1000 // 30 seconds in CI, 1 second otherwise
197
- const pollInterval = 200 // Check every 200ms
196
+ const waitTime = process . env . CI ? 45 * 1000 : 1 * 1000 // 45 seconds in CI, 1 second otherwise
197
+ const pollInterval = 500 // Check every 500ms to reduce load
198
198
const startTime = new Date ( ) . getTime ( )
199
199
200
- // Poll for file existence using proper sleep mechanism
200
+ // Poll for file existence with exponential backoff-style intervals
201
+ let currentInterval = pollInterval
201
202
while ( new Date ( ) . getTime ( ) - startTime < waitTime ) {
202
203
if ( fs . existsSync ( dataFile ) ) {
203
204
break
204
205
}
205
- // Use spawnSync to create a proper non-CPU-intensive delay
206
- if ( os . platform ( ) === 'win32' ) {
207
- spawnSync ( 'ping' , [ '-n' , '1' , '-w' , pollInterval . toString ( ) , '127.0.0.1' ] , { stdio : 'ignore' } )
208
- } else {
209
- spawnSync ( 'sleep' , [ ( pollInterval / 1000 ) . toString ( ) ] , { stdio : 'ignore' } )
206
+
207
+ // Use a more efficient sleep mechanism
208
+ try {
209
+ if ( os . platform ( ) === 'win32' ) {
210
+ // Use timeout command which is more reliable than ping
211
+ spawnSync ( 'timeout' , [ '/t' , Math . ceil ( currentInterval / 1000 ) . toString ( ) ] , { stdio : 'ignore' } )
212
+ } else {
213
+ // Use sleep with fractional seconds for better precision
214
+ spawnSync ( 'sleep' , [ ( currentInterval / 1000 ) . toString ( ) ] , { stdio : 'ignore' } )
215
+ }
216
+ } catch ( err ) {
217
+ // Fallback to setTimeout-based delay if system commands fail
218
+ const end = new Date ( ) . getTime ( ) + currentInterval
219
+ while ( new Date ( ) . getTime ( ) < end ) {
220
+ // Small yield to prevent complete CPU lock
221
+ if ( new Date ( ) . getTime ( ) % 10 === 0 ) {
222
+ process . nextTick ( ( ) => { } )
223
+ }
224
+ }
210
225
}
226
+
227
+ // Gradually increase interval to reduce polling frequency over time
228
+ currentInterval = Math . min ( currentInterval * 1.2 , 2000 )
211
229
}
212
230
}
213
231
if ( ! fs . existsSync ( dataFile ) ) {
0 commit comments