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

const server = http.createServer(common.mustCall(function(req, res) {
  assert.strictEqual(res.writableFinished, false);
  res
    .on('finish', common.mustCall(() => {
      assert.strictEqual(res.writableFinished, true);
      server.close();
    }))
    .end();
}));

server.listen(0);

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

  assert.strictEqual(clientRequest.writableFinished, false);
  clientRequest
    .on('finish', common.mustCall(() => {
      assert.strictEqual(clientRequest.writableFinished, true);
    }))
    .end();
  assert.strictEqual(clientRequest.writableFinished, false);
}));