• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const http = require('http');
5
6// This test assesses whether long-running writes can complete
7// or timeout because the socket is not aware that the backing
8// stream is still writing.
9
10const writeSize = 3000000;
11let socket;
12
13const server = http.createServer(common.mustCall((req, res) => {
14  server.close();
15  const content = Buffer.alloc(writeSize, 0x44);
16
17  res.writeHead(200, {
18    'Content-Type': 'application/octet-stream',
19    'Content-Length': content.length.toString(),
20    'Vary': 'Accept-Encoding'
21  });
22
23  socket = res.socket;
24  const onTimeout = socket._onTimeout;
25  socket._onTimeout = common.mustCallAtLeast(() => onTimeout.call(socket), 1);
26  res.write(content);
27  res.end();
28}));
29server.on('timeout', () => {
30  // TODO(apapirovski): This test is faulty on certain Windows systems
31  // as no queue is ever created
32  assert(!socket._handle || socket._handle.writeQueueSize === 0,
33         'Should not timeout');
34});
35
36server.listen(0, common.mustCall(() => {
37  http.get({
38    path: '/',
39    port: server.address().port
40  }, (res) => {
41    res.once('data', () => {
42      socket._onTimeout();
43      res.on('data', () => {});
44    });
45    res.on('end', () => server.close());
46  });
47}));
48