summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-outgoing-end-multiple.js
blob: 696443f9390cd024a25cd578545a4fe7831a6480 (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
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');

const onWriteAfterEndError = common.mustCall((err) => {
  assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END');
}, 2);

const server = http.createServer(common.mustCall(function(req, res) {
  res.end('testing ended state', common.mustCall());
  assert.strictEqual(res.writableCorked, 0);
  res.end(common.mustCall((err) => {
    assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED');
  }));
  assert.strictEqual(res.writableCorked, 0);
  res.end('end', onWriteAfterEndError);
  assert.strictEqual(res.writableCorked, 0);
  res.on('error', onWriteAfterEndError);
  res.on('finish', common.mustCall(() => {
    res.end(common.mustCall((err) => {
      assert.strictEqual(err.code, 'ERR_STREAM_ALREADY_FINISHED');
      server.close();
    }));
  }));
}));

server.listen(0);

server.on('listening', common.mustCall(function() {
  http
    .request({
      port: server.address().port,
      method: 'GET',
      path: '/'
    })
    .end();
}));