@@ -2503,6 +2503,54 @@ describe('ManageChannelsClient', () => {
2503
2503
expect ( calledCallBack ) . to . be . true ;
2504
2504
} ) ;
2505
2505
2506
+ it ( 'Can connect and write successfully after destroy' , async ( ) => {
2507
+ let didRequest = false ;
2508
+ let establishedConnections = 0 ;
2509
+ let requestsServed = 0 ;
2510
+ const method = HTTP2_METHOD_POST ;
2511
+ const path = PATH_CHANNELS ;
2512
+ server = createAndStartMockServer ( TEST_PORT , ( req , res , requestBody ) => {
2513
+ expect ( req . headers ) . to . deep . equal ( {
2514
+ ':authority' : '127.0.0.1' ,
2515
+ ':method' : method ,
2516
+ ':path' : path ,
2517
+ ':scheme' : 'https' ,
2518
+ 'apns-someheader' : 'somevalue' ,
2519
+ } ) ;
2520
+ expect ( requestBody ) . to . equal ( MOCK_BODY ) ;
2521
+ // res.setHeader('X-Foo', 'bar');
2522
+ // res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
2523
+ res . writeHead ( 200 ) ;
2524
+ res . end ( '' ) ;
2525
+ requestsServed += 1 ;
2526
+ didRequest = true ;
2527
+ } ) ;
2528
+ server . on ( 'connection' , ( ) => ( establishedConnections += 1 ) ) ;
2529
+ await new Promise ( resolve => server . on ( 'listening' , resolve ) ) ;
2530
+ client = createClient ( CLIENT_TEST_PORT ) ;
2531
+
2532
+ const mockHeaders = { 'apns-someheader' : 'somevalue' } ;
2533
+ const mockNotification = {
2534
+ headers : mockHeaders ,
2535
+ body : MOCK_BODY ,
2536
+ } ;
2537
+ const performRequestExpectingDisconnect = async ( ) => {
2538
+ const bundleId = BUNDLE_ID ;
2539
+ const method = 'post' ;
2540
+
2541
+ await client . write ( mockNotification , bundleId , 'channels' , method ) ;
2542
+ expect ( didRequest ) . to . be . true ;
2543
+ expect ( establishedConnections ) . to . equal ( 1 ) ;
2544
+ expect ( requestsServed ) . to . equal ( 1 ) ;
2545
+
2546
+ await client . destroySession ( client . manageChannelsSession ) ;
2547
+ await client . write ( mockNotification , bundleId , 'channels' , method ) ;
2548
+ expect ( establishedConnections ) . to . equal ( 2 ) ;
2549
+ expect ( requestsServed ) . to . equal ( 2 ) ;
2550
+ } ;
2551
+ await performRequestExpectingDisconnect ( ) ;
2552
+ } ) ;
2553
+
2506
2554
it ( 'Establishes a connection through a proxy server' , async ( ) => {
2507
2555
let didRequest = false ;
2508
2556
let establishedConnections = 0 ;
0 commit comments