@@ -39,41 +39,35 @@ const updatedValues = new Map([
39
39
[ 'sessionIdContext' , 'sessionIdContext' ] ,
40
40
] ) ;
41
41
42
+ let value ;
42
43
function variations ( iter , port , cb ) {
43
- const { done, value } = iter . next ( ) ;
44
- if ( done ) {
45
- return common . mustCall ( ( res ) => {
46
- res . resume ( ) ;
47
- https . globalAgent . once ( 'free' , common . mustCall ( ( ) => {
48
- // Verify that different keep-alived connections are created
49
- // for the base call and each variation
50
- const keys = Object . keys ( https . globalAgent . freeSockets ) ;
51
- assert . strictEqual ( keys . length , 1 + updatedValues . size ) ;
52
- let i = 1 ;
53
- for ( const [ , value ] of updatedValues ) {
54
- assert . ok (
55
- keys [ i ] . startsWith ( value . toString ( ) + ':' ) ||
56
- keys [ i ] . endsWith ( ':' + value . toString ( ) ) ||
57
- keys [ i ] . includes ( ':' + value . toString ( ) + ':' )
58
- ) ;
59
- i ++ ;
60
- }
44
+ return common . mustCall ( ( res ) => {
45
+ res . resume ( ) ;
46
+ https . globalAgent . once ( 'free' , common . mustCall ( ( ) => {
47
+ // Verify that the most recent connection is in the freeSockets pool.
48
+ const keys = Object . keys ( https . globalAgent . freeSockets ) ;
49
+ if ( value ) {
50
+ assert . ok (
51
+ keys . some ( ( val ) => val . startsWith ( value . toString ( ) + ':' ) ||
52
+ val . endsWith ( ':' + value . toString ( ) ) ||
53
+ val . includes ( ':' + value . toString ( ) + ':' ) ) ,
54
+ `missing value: ${ value . toString ( ) } in ${ keys } `
55
+ ) ;
56
+ }
57
+ const next = iter . next ( ) ;
58
+
59
+ if ( next . done ) {
61
60
https . globalAgent . destroy ( ) ;
62
61
server . close ( ) ;
63
- } ) ) ;
64
- } ) ;
65
- } else {
66
- const [ key , val ] = value ;
67
- return common . mustCall ( ( res ) => {
68
- res . resume ( ) ;
69
- https . globalAgent . once ( 'free' , common . mustCall ( ( ) => {
70
- https . get (
71
- Object . assign ( { } , getBaseOptions ( port ) , { [ key ] : val } ) ,
72
- variations ( iter , port , cb )
73
- ) ;
74
- } ) ) ;
75
- } ) ;
76
- }
62
+ } else {
63
+ // Save `value` for check the next time.
64
+ value = next . value . val ;
65
+ const [ key , val ] = next . value ;
66
+ https . get ( Object . assign ( { } , getBaseOptions ( port ) , { [ key ] : val } ) ,
67
+ variations ( iter , port , cb ) ) ;
68
+ }
69
+ } ) ) ;
70
+ } ) ;
77
71
}
78
72
79
73
server . listen ( 0 , common . mustCall ( ( ) => {
0 commit comments