summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-pause-resume-one-end.js
blob: 76969775e604ccea61afcba9b5632c2fb980f6ff (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
'use strict';
require('../common');
var assert = require('assert');
var http = require('http');

var server = http.Server(function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
  server.close();
});


var dataCount = 0, endCount = 0;

server.listen(0, function() {
  var opts = {
    port: this.address().port,
    headers: { connection: 'close' }
  };

  http.get(opts, function(res) {
    res.on('data', function(chunk) {
      dataCount++;
      res.pause();
      setTimeout(function() {
        res.resume();
      });
    });

    res.on('end', function() {
      endCount++;
    });
  });
});


process.on('exit', function() {
  assert.equal(1, dataCount);
  assert.equal(1, endCount);
});