88// connect and heard nothing at all.
99
1010import { hasCrypto , mustCall , skip } from '../common/index.mjs' ;
11+ import { setTimeout } from 'node:timers/promises' ;
1112import * as fixtures from '../common/fixtures.mjs' ;
1213import assert from 'node:assert' ;
1314
@@ -36,18 +37,10 @@ async function within(promise, what, ms = 5000) {
3637 const late = Symbol ( 'late' ) ;
3738 // The timer has to be cleared: left pending it holds the loop open for its
3839 // full duration after the race is already decided.
39- let timer ;
40- try {
41- const result = await Promise . race ( [
42- promise ,
43- new Promise ( ( resolve ) => { timer = setTimeout ( resolve , ms , late ) ; } ) ,
44- ] ) ;
45- assert . notStrictEqual ( result , late ,
46- `${ what } did not happen within ${ ms } ms` ) ;
47- return result ;
48- } finally {
49- clearTimeout ( timer ) ;
50- }
40+ const result = await Promise . race ( [ promise , setTimeout ( ms , late , { ref : false } ) ] ) ;
41+ assert . notStrictEqual ( result , late ,
42+ `${ what } did not happen within ${ ms } ms` ) ;
43+ return result ;
5144}
5245const key = ( name ) => fixtures . readKey ( name ) . toString ( ) ;
5346const cert = key ( 'agent1-cert.pem' ) ;
@@ -137,7 +130,7 @@ const privateKey = key('agent1-key.pem');
137130 const pending = Symbol ( 'pending' ) ;
138131 await Promise . race ( [
139132 client . opened . then ( ( ) => 'opened' , ( ) => 'failed' ) ,
140- new Promise ( ( resolve ) => setTimeout ( resolve , 300 , pending ) ) ,
133+ setTimeout ( 300 , pending ) ,
141134 ] ) ;
142135
143136 assert . strictEqual ( Number ( getDTLSEndpointState ( endpoint ) . sessionCount ) , 0 ) ;
@@ -148,7 +141,7 @@ const privateKey = key('agent1-key.pem');
148141 } ) ;
149142 const outcome = await Promise . race ( [
150143 good . opened . then ( ( ) => 'opened' , ( ) => 'failed' ) ,
151- new Promise ( ( resolve ) => setTimeout ( resolve , 500 , pending ) ) ,
144+ setTimeout ( 500 , pending ) ,
152145 ] ) ;
153146 assert . notStrictEqual ( outcome , pending ) ;
154147
0 commit comments