@@ -10,6 +10,7 @@ const credentials = require('../lib/credentials')({
10
10
} ) ;
11
11
12
12
const TEST_PORT = 30939 ;
13
+ const CLIENT_TEST_PORT = TEST_PORT + 1 ;
13
14
const LOAD_TEST_BATCH_SIZE = 2000 ;
14
15
15
16
const config = require ( '../lib/config' ) ( {
@@ -152,7 +153,7 @@ describe('Client', () => {
152
153
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
153
154
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
154
155
155
- client = createClient ( TEST_PORT ) ;
156
+ client = createClient ( CLIENT_TEST_PORT ) ;
156
157
157
158
const runSuccessfulRequest = async ( ) => {
158
159
const mockHeaders = { 'apns-someheader' : 'somevalue' } ;
@@ -206,7 +207,7 @@ describe('Client', () => {
206
207
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
207
208
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
208
209
209
- client = createClient ( TEST_PORT ) ;
210
+ client = createClient ( CLIENT_TEST_PORT ) ;
210
211
211
212
const runSuccessfulRequest = async ( ) => {
212
213
const mockHeaders = { 'apns-someheader' : 'somevalue' } ;
@@ -261,7 +262,7 @@ describe('Client', () => {
261
262
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
262
263
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
263
264
264
- client = createClient ( TEST_PORT , 1500 ) ;
265
+ client = createClient ( CLIENT_TEST_PORT , 1500 ) ;
265
266
266
267
const runSuccessfulRequest = async ( ) => {
267
268
const mockHeaders = { 'apns-someheader' : 'somevalue' } ;
@@ -312,7 +313,7 @@ describe('Client', () => {
312
313
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
313
314
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
314
315
315
- client = createClient ( TEST_PORT , 500 , pingDelay ) ;
316
+ client = createClient ( CLIENT_TEST_PORT , 500 , pingDelay ) ;
316
317
317
318
// Setup logger.
318
319
const infoMessages = [ ] ;
@@ -369,7 +370,7 @@ describe('Client', () => {
369
370
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
370
371
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
371
372
372
- client = createClient ( TEST_PORT ) ;
373
+ client = createClient ( CLIENT_TEST_PORT ) ;
373
374
const infoMessages = [ ] ;
374
375
const errorMessages = [ ] ;
375
376
const mockInfoLogger = message => {
@@ -431,7 +432,7 @@ describe('Client', () => {
431
432
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
432
433
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
433
434
434
- client = createClient ( TEST_PORT ) ;
435
+ client = createClient ( CLIENT_TEST_PORT ) ;
435
436
436
437
// Setup logger.
437
438
const infoMessages = [ ] ;
@@ -514,7 +515,7 @@ describe('Client', () => {
514
515
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
515
516
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
516
517
517
- client = createClient ( TEST_PORT ) ;
518
+ client = createClient ( CLIENT_TEST_PORT ) ;
518
519
519
520
const runRequestWithInternalServerError = async ( ) => {
520
521
const mockHeaders = { 'apns-someheader' : 'somevalue' } ;
@@ -564,7 +565,7 @@ describe('Client', () => {
564
565
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
565
566
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
566
567
567
- client = createClient ( TEST_PORT ) ;
568
+ client = createClient ( CLIENT_TEST_PORT ) ;
568
569
569
570
const runRequestWithInternalServerError = async ( ) => {
570
571
const mockHeaders = { 'apns-someheader' : 'somevalue' } ;
@@ -604,7 +605,7 @@ describe('Client', () => {
604
605
didGetResponse = true ;
605
606
} , 1900 ) ;
606
607
} ) ;
607
- client = createClient ( TEST_PORT ) ;
608
+ client = createClient ( CLIENT_TEST_PORT ) ;
608
609
609
610
const onListeningPromise = new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
610
611
await onListeningPromise ;
@@ -652,7 +653,7 @@ describe('Client', () => {
652
653
session . goaway ( errorCode ) ;
653
654
} ) ;
654
655
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
655
- client = createClient ( TEST_PORT ) ;
656
+ client = createClient ( CLIENT_TEST_PORT ) ;
656
657
657
658
// Setup logger.
658
659
const infoMessages = [ ] ;
@@ -719,7 +720,7 @@ describe('Client', () => {
719
720
} , responseTimeout ) ;
720
721
} ) ;
721
722
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
722
- client = createClient ( TEST_PORT ) ;
723
+ client = createClient ( CLIENT_TEST_PORT ) ;
723
724
724
725
// Setup logger.
725
726
const infoMessages = [ ] ;
@@ -839,7 +840,7 @@ describe('Client', () => {
839
840
proxy . unref ( ) ;
840
841
841
842
// Client configured with a port that the server is not listening on
842
- client = createClient ( TEST_PORT + 1 ) ;
843
+ client = createClient ( CLIENT_TEST_PORT ) ;
843
844
// So without adding a proxy config request will fail with a network error
844
845
client . config . proxy = { host : '127.0.0.1' , port : proxyPort } ;
845
846
const runSuccessfulRequest = async ( ) => {
@@ -880,7 +881,7 @@ describe('Client', () => {
880
881
881
882
it ( 'Throws an error when there is a bad proxy server' , async ( ) => {
882
883
// Client configured with a port that the server is not listening on
883
- client = createClient ( TEST_PORT ) ;
884
+ client = createClient ( CLIENT_TEST_PORT ) ;
884
885
// So without adding a proxy config request will fail with a network error
885
886
client . config . proxy = { host : '127.0.0.1' , port : 'NOT_A_PORT' } ;
886
887
@@ -1630,7 +1631,7 @@ describe('ManageChannelsClient', () => {
1630
1631
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
1631
1632
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
1632
1633
1633
- client = createClient ( TEST_PORT ) ;
1634
+ client = createClient ( CLIENT_TEST_PORT ) ;
1634
1635
1635
1636
const runSuccessfulRequest = async ( ) => {
1636
1637
const mockHeaders = { 'apns-someheader' : 'somevalue' } ;
@@ -1684,7 +1685,7 @@ describe('ManageChannelsClient', () => {
1684
1685
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
1685
1686
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
1686
1687
1687
- client = createClient ( TEST_PORT ) ;
1688
+ client = createClient ( CLIENT_TEST_PORT ) ;
1688
1689
1689
1690
const runSuccessfulRequest = async ( ) => {
1690
1691
const mockHeaders = { 'apns-someheader' : 'somevalue' } ;
@@ -1739,7 +1740,7 @@ describe('ManageChannelsClient', () => {
1739
1740
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
1740
1741
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
1741
1742
1742
- client = createClient ( TEST_PORT , 1500 ) ;
1743
+ client = createClient ( CLIENT_TEST_PORT , 1500 ) ;
1743
1744
1744
1745
const runSuccessfulRequest = async ( ) => {
1745
1746
const mockHeaders = { 'apns-someheader' : 'somevalue' } ;
@@ -1790,7 +1791,7 @@ describe('ManageChannelsClient', () => {
1790
1791
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
1791
1792
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
1792
1793
1793
- client = createClient ( TEST_PORT , 500 , pingDelay ) ;
1794
+ client = createClient ( CLIENT_TEST_PORT , 500 , pingDelay ) ;
1794
1795
1795
1796
// Setup logger.
1796
1797
const infoMessages = [ ] ;
@@ -1847,7 +1848,7 @@ describe('ManageChannelsClient', () => {
1847
1848
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
1848
1849
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
1849
1850
1850
- client = createClient ( TEST_PORT ) ;
1851
+ client = createClient ( CLIENT_TEST_PORT ) ;
1851
1852
const infoMessages = [ ] ;
1852
1853
const errorMessages = [ ] ;
1853
1854
const mockInfoLogger = message => {
@@ -1909,7 +1910,7 @@ describe('ManageChannelsClient', () => {
1909
1910
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
1910
1911
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
1911
1912
1912
- client = createClient ( TEST_PORT ) ;
1913
+ client = createClient ( CLIENT_TEST_PORT ) ;
1913
1914
1914
1915
// Setup logger.
1915
1916
const infoMessages = [ ] ;
@@ -1990,7 +1991,7 @@ describe('ManageChannelsClient', () => {
1990
1991
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
1991
1992
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
1992
1993
1993
- client = createClient ( TEST_PORT ) ;
1994
+ client = createClient ( CLIENT_TEST_PORT ) ;
1994
1995
1995
1996
// Setup logger.
1996
1997
const infoMessages = [ ] ;
@@ -2072,7 +2073,7 @@ describe('ManageChannelsClient', () => {
2072
2073
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
2073
2074
await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
2074
2075
2075
- client = createClient ( TEST_PORT ) ;
2076
+ client = createClient ( CLIENT_TEST_PORT ) ;
2076
2077
2077
2078
// Setup logger.
2078
2079
const infoMessages = [ ] ;
@@ -2145,7 +2146,7 @@ describe('ManageChannelsClient', () => {
2145
2146
didGetResponse = true ;
2146
2147
} , 1900 ) ;
2147
2148
} ) ;
2148
- client = createClient ( TEST_PORT ) ;
2149
+ client = createClient ( CLIENT_TEST_PORT ) ;
2149
2150
2150
2151
// Setup logger.
2151
2152
const infoMessages = [ ] ;
@@ -2226,7 +2227,7 @@ describe('ManageChannelsClient', () => {
2226
2227
session . goaway ( errorCode ) ;
2227
2228
} ) ;
2228
2229
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
2229
- client = createClient ( TEST_PORT ) ;
2230
+ client = createClient ( CLIENT_TEST_PORT ) ;
2230
2231
2231
2232
// Setup logger.
2232
2233
const infoMessages = [ ] ;
@@ -2293,7 +2294,7 @@ describe('ManageChannelsClient', () => {
2293
2294
} , responseTimeout ) ;
2294
2295
} ) ;
2295
2296
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
2296
- client = createClient ( TEST_PORT ) ;
2297
+ client = createClient ( CLIENT_TEST_PORT ) ;
2297
2298
2298
2299
// Setup logger.
2299
2300
const infoMessages = [ ] ;
@@ -2380,7 +2381,7 @@ describe('ManageChannelsClient', () => {
2380
2381
} , responseTimeout ) ;
2381
2382
} ) ;
2382
2383
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
2383
- client = createClient ( TEST_PORT ) ;
2384
+ client = createClient ( CLIENT_TEST_PORT ) ;
2384
2385
2385
2386
const onListeningPromise = new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
2386
2387
await onListeningPromise ;
@@ -2422,7 +2423,7 @@ describe('ManageChannelsClient', () => {
2422
2423
} , responseTimeout ) ;
2423
2424
} ) ;
2424
2425
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
2425
- client = createClient ( TEST_PORT ) ;
2426
+ client = createClient ( CLIENT_TEST_PORT ) ;
2426
2427
2427
2428
const onListeningPromise = new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
2428
2429
await onListeningPromise ;
@@ -2465,7 +2466,7 @@ describe('ManageChannelsClient', () => {
2465
2466
} , responseTimeout ) ;
2466
2467
} ) ;
2467
2468
server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
2468
- client = createClient ( TEST_PORT ) ;
2469
+ client = createClient ( CLIENT_TEST_PORT ) ;
2469
2470
2470
2471
const onListeningPromise = new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
2471
2472
await onListeningPromise ;
@@ -2493,15 +2494,20 @@ describe('ManageChannelsClient', () => {
2493
2494
await performRequestExpectingDisconnect ( ) ;
2494
2495
expect ( didGetRequest ) . to . be . false ;
2495
2496
expect ( establishedConnections ) . to . equal ( 0 ) ;
2497
+ let calledCallBack = false ;
2498
+ await client . shutdown ( ( ) => {
2499
+ calledCallBack = true ;
2500
+ } ) ;
2501
+ expect ( calledCallBack ) . to . be . true ;
2496
2502
} ) ;
2497
-
2503
+ /*
2498
2504
it('Establishes a connection through a proxy server', async () => {
2499
2505
let didRequest = false;
2500
2506
let establishedConnections = 0;
2501
2507
let requestsServed = 0;
2502
2508
const method = HTTP2_METHOD_POST;
2503
2509
const path = PATH_CHANNELS;
2504
- const proxyPort = TEST_PORT - 1 ;
2510
+ const proxyPort = TEST_PORT - 2 ;
2505
2511
2506
2512
server = createAndStartMockServer(TEST_PORT, (req, res, requestBody) => {
2507
2513
expect(req.headers).to.deep.equal({
@@ -2546,9 +2552,9 @@ describe('ManageChannelsClient', () => {
2546
2552
proxy.unref();
2547
2553
2548
2554
// Client configured with a port that the server is not listening on
2549
- client = createClient ( TEST_PORT + 1 ) ;
2555
+ client = createClient(CLIENT_TEST_PORT );
2550
2556
// So without adding a proxy config request will fail with a network error
2551
- // client.config.manageChannelsProxy = { host: '127.0.0.1', port: proxyPort };
2557
+ client.config.manageChannelsProxy = { host: '127.0.0.1', port: proxyPort };
2552
2558
const runSuccessfulRequest = async () => {
2553
2559
const mockHeaders = { 'apns-someheader': 'somevalue' };
2554
2560
const mockNotification = {
@@ -2584,10 +2590,10 @@ describe('ManageChannelsClient', () => {
2584
2590
});
2585
2591
proxy = null;
2586
2592
});
2587
-
2593
+ */
2588
2594
it ( 'Throws an error when there is a bad proxy server' , async ( ) => {
2589
2595
// Client configured with a port that the server is not listening on
2590
- client = createClient ( TEST_PORT ) ;
2596
+ client = createClient ( CLIENT_TEST_PORT ) ;
2591
2597
// So without adding a proxy config request will fail with a network error
2592
2598
client . config . manageChannelsProxy = { host : '127.0.0.1' , port : 'NOT_A_PORT' } ;
2593
2599
0 commit comments