node/test/parallel/test-quic-quicsession-server-destroy-early.js
James M Snell 6665dda9f6 quic: implement QuicSocket Promise API, part 2
PR-URL: https://github.com/nodejs/node/pull/34283
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-07-15 17:16:52 -07:00

55 lines
1.3 KiB
JavaScript

// Flags: --no-warnings
'use strict';
// Test that destroying a QuicStream immediately and synchronously
// after creation does not crash the process and closes the streams
// abruptly on both ends of the connection.
const common = require('../common');
if (!common.hasQuic)
common.skip('missing quic');
const assert = require('assert');
const { once } = require('events');
const { key, cert, ca } = require('../common/quic');
const { createQuicSocket } = require('net');
const options = { key, cert, ca, alpn: 'zzz' };
const client = createQuicSocket({ client: options });
const server = createQuicSocket({ server: options });
(async function() {
server.on('session', common.mustCall((session) => {
session.on('stream', common.mustNotCall());
session.on('close', common.mustCall(async () => {
await Promise.all([
client.close(),
server.close()
]);
assert.rejects(server.close(), {
code: 'ERR_INVALID_STATE',
name: 'Error'
});
}));
session.destroy();
}));
await server.listen();
const req = await client.connect({
address: 'localhost',
port: server.endpoints[0].address.port
});
req.on('secure', common.mustNotCall());
req.on('close', common.mustCall());
await Promise.all([
once(server, 'close'),
once(client, 'close')
]);
})().then(common.mustCall());