summaryrefslogtreecommitdiff
path: root/test/parallel/test-quic-quicsession-server-destroy-early.js
blob: 011afea837684f5241fb602dfb7d4622a9773fa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 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());