Skip to content

Commit 065e88c

Browse files
committed
add destroySession test
1 parent 354242d commit 065e88c

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lib/client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ module.exports = function (dependencies) {
8080
return;
8181
}
8282
if (!session.destroyed) {
83+
console.log('3333333 ');
8384
session.destroy();
8485
}
8586
session = null;

test/client.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,6 +2503,54 @@ describe('ManageChannelsClient', () => {
25032503
expect(calledCallBack).to.be.true;
25042504
});
25052505

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+
25062554
it('Establishes a connection through a proxy server', async () => {
25072555
let didRequest = false;
25082556
let establishedConnections = 0;

0 commit comments

Comments
 (0)