summaryrefslogtreecommitdiff
path: root/test/parallel/test-quic-quicsession-send-file-open-error.js
blob: 5d96c5c82b3c899ccf24380a4fa501a94a0af6c0 (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
// Flags: --no-warnings
'use strict';
const common = require('../common');
if (!common.hasQuic)
  common.skip('missing quic');

const path = require('path');
const { createQuicSocket } = require('net');
const { once } = require('events');

const { key, cert, ca } = require('../common/quic');
const options = { key, cert, ca, alpn: 'meow' };

const server = createQuicSocket({ server: options });
const client = createQuicSocket({ client: options });

(async function() {
  server.on('session', common.mustCall(async (session) => {
    const stream = await session.openStream({ halfOpen: false });
    const nonexistentPath = path.resolve(__dirname, 'nonexistent.file');
    stream.on('error', common.expectsError({
      code: 'ENOENT',
      syscall: 'open',
      path: nonexistentPath
    }));
    stream.sendFile(nonexistentPath);
    session.close();

    session.on('close', common.mustCall());
  }));

  await server.listen();

  const req = await client.connect({
    address: 'localhost',
    port: server.endpoints[0].address.port
  });

  req.on('stream', common.mustNotCall());

  req.on('close', common.mustCall(() => {
    server.close();
    client.close();
  }));

  await Promise.all([
    once(server, 'close'),
    once(client, 'close')
  ]);

})().then(common.mustCall());