@@ -53,16 +53,11 @@ describe('Dial Request', () => {
53
53
54
54
it ( 'should release tokens when all addr dials have started' , async ( ) => {
55
55
const mockConnection = await createMockConnection ( )
56
+ const firstDials = pDefer ( )
56
57
const deferred = pDefer ( )
57
58
const actions = {
58
- 1 : async ( ) => {
59
- await delay ( 0 )
60
- return Promise . reject ( error )
61
- } ,
62
- 2 : async ( ) => {
63
- await delay ( 0 )
64
- return Promise . reject ( error )
65
- } ,
59
+ 1 : ( ) => firstDials . promise ,
60
+ 2 : ( ) => firstDials . promise ,
66
61
3 : ( ) => deferred . promise
67
62
}
68
63
const dialAction = ( num ) => actions [ num ] ( )
@@ -85,15 +80,19 @@ describe('Dial Request', () => {
85
80
sinon . spy ( dialer , 'releaseToken' )
86
81
dialRequest . run ( { signal : controller . signal } )
87
82
// Let the first dials run
88
- await delay ( 100 )
83
+ await delay ( 0 )
84
+
85
+ // Finish the first 2 dials
86
+ firstDials . reject ( error )
87
+ await delay ( 0 )
89
88
90
89
// Only 1 dial should remain, so 1 token should have been released
91
90
expect ( actions [ 1 ] ) . to . have . property ( 'callCount' , 1 )
92
91
expect ( actions [ 2 ] ) . to . have . property ( 'callCount' , 1 )
93
92
expect ( actions [ 3 ] ) . to . have . property ( 'callCount' , 1 )
94
93
expect ( dialer . releaseToken ) . to . have . property ( 'callCount' , 1 )
95
94
96
- // Finish the dial
95
+ // Finish the dial and release the 2nd token
97
96
deferred . resolve ( mockConnection )
98
97
await delay ( 0 )
99
98
expect ( dialer . releaseToken ) . to . have . property ( 'callCount' , 2 )
0 commit comments