Skip to content

Commit

Permalink
test: use mustCall(), not global state checks
Browse files Browse the repository at this point in the history
Instead of pushing state into global arrays and checking the results
before exit, use common.mustCall() and make the checks immediately.

PR-URL: #25508
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
sam-github authored and addaleax committed Feb 7, 2019
1 parent 50d2c8e commit 1be8676
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions test/parallel/test-tls-socket-constructor-alpn-options-parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const fixtures = require('../common/fixtures');
const key = fixtures.readKey('agent1-key.pem');
const cert = fixtures.readKey('agent1-cert.pem');

const protocols = [];

const server = net.createServer(common.mustCall((s) => {
const tlsSocket = new tls.TLSSocket(s, {
isServer: true,
Expand All @@ -32,10 +30,9 @@ const server = net.createServer(common.mustCall((s) => {
});

tlsSocket.on('secure', common.mustCall(() => {
protocols.push({
alpnProtocol: tlsSocket.alpnProtocol,
});
assert.strictEqual(tlsSocket.alpnProtocol, 'http/1.1');
tlsSocket.end();
server.close();
}));
}));

Expand All @@ -46,13 +43,7 @@ server.listen(0, common.mustCall(() => {
ALPNProtocols: ['h2', 'http/1.1']
};

tls.connect(alpnOpts, function() {
tls.connect(alpnOpts, common.mustCall(function() {
this.end();

server.close();

assert.deepStrictEqual(protocols, [
{ alpnProtocol: 'http/1.1' },
]);
});
}));
}));

0 comments on commit 1be8676

Please sign in to comment.