@@ -192,36 +192,38 @@ module.exports.test = {
192192 submittedData ( dataFile ) {
193193 return function ( key ) {
194194 if ( ! fs . existsSync ( dataFile ) ) {
195- // Reduce wait time while maintaining reliability across different environments
196- const waitTime = process . env . CI ? 30 * 1000 : 1 * 1000 // 30 seconds in CI, 1 second otherwise
197- const pollInterval = 250 // Check every 250ms for faster detection
195+ // Extended timeout for CI environments to handle slower processing
196+ const waitTime = process . env . CI ? 60 * 1000 : 2 * 1000 // 60 seconds in CI, 2 seconds otherwise
197+ let pollInterval = 100 // Start with 100ms polling interval
198+ const maxPollInterval = 2000 // Max 2 second intervals
198199 const startTime = new Date ( ) . getTime ( )
199200
200- // Poll for file existence with optimized intervals
201+ // Synchronous polling with exponential backoff to reduce CPU usage
201202 while ( new Date ( ) . getTime ( ) - startTime < waitTime ) {
202203 if ( fs . existsSync ( dataFile ) ) {
203204 break
204205 }
205206
206- // Use a more efficient sleep mechanism
207+ // Use Node.js child_process.spawnSync with platform-specific sleep commands
208+ // This avoids busy waiting and allows other processes to run
207209 try {
208210 if ( os . platform ( ) === 'win32' ) {
209- // Use timeout command which is more reliable than ping
210- spawnSync ( 'timeout ' , [ '/t ' , '1' ] , { stdio : 'ignore' } )
211+ // Windows: use ping with precise timing (ping waits exactly the specified ms)
212+ spawnSync ( 'ping ' , [ '-n ' , '1' , '-w' , pollInterval . toString ( ) , '127.0.0. 1'] , { stdio : 'ignore' } )
211213 } else {
212- // Use sleep with fractional seconds for better precision
214+ // Unix/Linux/macOS: use sleep with fractional seconds
213215 spawnSync ( 'sleep' , [ ( pollInterval / 1000 ) . toString ( ) ] , { stdio : 'ignore' } )
214216 }
215217 } catch ( err ) {
216- // Fallback to setTimeout-based delay if system commands fail
218+ // If system commands fail, use a simple busy wait with minimal CPU usage
217219 const end = new Date ( ) . getTime ( ) + pollInterval
218220 while ( new Date ( ) . getTime ( ) < end ) {
219- // Small yield to prevent complete CPU lock
220- if ( new Date ( ) . getTime ( ) % 10 === 0 ) {
221- process . nextTick ( ( ) => { } )
222- }
221+ // No-op loop - much lighter than previous approaches
223222 }
224223 }
224+
225+ // Exponential backoff: gradually increase polling interval to reduce resource usage
226+ pollInterval = Math . min ( pollInterval * 1.2 , maxPollInterval )
225227 }
226228 }
227229 if ( ! fs . existsSync ( dataFile ) ) {
0 commit comments