many.js 868 B

1234567891011121314151617181920212223242526272829303132333435
  1. var test = require('tape');
  2. var http = require('http');
  3. var hyperquest = require('../');
  4. var through = require('through2');
  5. var server = http.createServer(function (req, res) {
  6. res.write('beep boop');
  7. });
  8. test('more than 5 pending connections', function (t) {
  9. t.plan(20);
  10. var pending = [];
  11. server.listen(0, function () {
  12. var port = server.address().port;
  13. for (var i = 0; i < 20; i++) {
  14. pending.push(check(t, port));
  15. }
  16. });
  17. t.on('end', function () {
  18. pending.forEach(function (p) { p.destroy() });
  19. server.close();
  20. });
  21. });
  22. function check (t, port) {
  23. var r = hyperquest('http://localhost:' + port);
  24. var data = '';
  25. r.pipe(through(function (buf, enc, cb) { data += buf; cb() }));
  26. setTimeout(function () {
  27. t.equal(data, 'beep boop');
  28. }, 100);
  29. return r;
  30. }