File tree Expand file tree Collapse file tree 5 files changed +4
-24
lines changed
Expand file tree Collapse file tree 5 files changed +4
-24
lines changed Original file line number Diff line number Diff line change @@ -1148,19 +1148,15 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
11481148 * `false` otherwise
11491149 */
11501150 protected async _isClientDoneProcessing ( timeout ?: number ) : Promise < boolean > {
1151- // Early exit if there's nothing to process
11521151 if ( ! this . _numProcessing ) {
11531152 return true ;
11541153 }
11551154
11561155 let ticked = 0 ;
11571156
1158- // if no timeout is provided, we wait "forever" until everything is processed
11591157 while ( ! timeout || ticked < timeout ) {
11601158 await new Promise ( resolve => {
11611159 const timer = setTimeout ( resolve , 1 ) ;
1162- // Use unref() in Node.js to allow the process to exit naturally
1163- // In browsers, setTimeout returns a number, so we check for that
11641160 if ( typeof timer !== 'number' && timer . unref ) {
11651161 timer . unref ( ) ;
11661162 }
Original file line number Diff line number Diff line change @@ -81,16 +81,12 @@ export function makePromiseBuffer<T>(limit: number = 100): PromiseBuffer<T> {
8181 drainPromise ,
8282 new Promise < boolean > ( resolve => {
8383 const timer = setTimeout ( ( ) => resolve ( false ) , timeout ) ;
84- // Use unref() in Node.js to allow the process to exit naturally
85- // In browsers, setTimeout returns a number, so we check for that
8684 if ( typeof timer !== 'number' && timer . unref ) {
8785 timer . unref ( ) ;
8886 }
8987 } ) ,
9088 ] ;
9189
92- // Promise.race will resolve to the first promise that resolves or rejects
93- // So if the drainPromise resolves, the timeout promise will be ignored
9490 return Promise . race ( promises ) ;
9591 }
9692
Original file line number Diff line number Diff line change @@ -2217,9 +2217,7 @@ describe('Client', () => {
22172217 const result = await client . flush ( 1000 ) ;
22182218 const elapsed = Date . now ( ) - startTime ;
22192219
2220- // Should return true immediately without waiting
22212220 expect ( result ) . toBe ( true ) ;
2222- // Should take less than 100ms (much less than the 1000ms timeout)
22232221 expect ( elapsed ) . toBeLessThan ( 100 ) ;
22242222 } ) ;
22252223
@@ -2241,13 +2239,12 @@ describe('Client', () => {
22412239 expect ( getSendCalled ( ) ) . toEqual ( 1 ) ;
22422240
22432241 const startTime = Date . now ( ) ;
2244- // Use a large timeout but processing should complete early
22452242 await client . flush ( 5000 ) ;
22462243 const elapsed = Date . now ( ) - startTime ;
22472244
22482245 expect ( getSentCount ( ) ) . toEqual ( 1 ) ;
2249- // Should complete in ~50ms (the transport delay), not wait for the full 5000ms timeout
2250- expect ( elapsed ) . toBeLessThan ( 500 ) ;
2246+ // if this flakes, remove the test
2247+ expect ( elapsed ) . toBeLessThan ( 1000 ) ;
22512248 } ) ;
22522249 } ) ;
22532250
Original file line number Diff line number Diff line change @@ -262,7 +262,6 @@ describe('PromiseBuffer', () => {
262262 const elapsed = Date . now ( ) - startTime ;
263263
264264 expect ( result ) . toBe ( true ) ;
265- // Should return immediately, not wait for timeout
266265 expect ( elapsed ) . toBeLessThan ( 100 ) ;
267266 } ) ;
268267} ) ;
Original file line number Diff line number Diff line change @@ -396,23 +396,15 @@ describe('NodeClient', () => {
396396 const result = await client . flush ( 1000 ) ;
397397 const elapsed = Date . now ( ) - startTime ;
398398
399- // Should return true immediately without waiting
400399 expect ( result ) . toBe ( true ) ;
401- // Should take less than 100ms (much less than the 1000ms timeout)
402400 expect ( elapsed ) . toBeLessThan ( 100 ) ;
403401 } ) ;
404402
405- it ( 'flush does not block process exit when using unref timers' , async ( ) => {
406- // This test verifies that timers are properly unref'd in Node.js
407- // We create a client with no processing and a long timeout
403+ it ( 'flush does not block process exit with unref timers' , async ( ) => {
408404 const options = getDefaultNodeClientOptions ( ) ;
409405 const client = new NodeClient ( options ) ;
410406
411- // Flush with a long timeout - if timers are not unref'd, this would block
412- const flushPromise = client . flush ( 5000 ) ;
413-
414- // The flush should complete immediately since there's nothing to process
415- const result = await flushPromise ;
407+ const result = await client . flush ( 5000 ) ;
416408 expect ( result ) . toBe ( true ) ;
417409 } ) ;
418410 } ) ;
You can’t perform that action at this time.
0 commit comments