test.js 639 B

12345678910111213141516171819202122232425262728293031
  1. var net = require('net');
  2. var assert = require('assert');
  3. var enableDestroy = require('./index.js');
  4. var server = net.createServer(function(conn) {
  5. var i = setInterval(function() {
  6. conn.read();
  7. conn.write('hi\n');
  8. }, 100);
  9. i.unref();
  10. });
  11. server.listen(1337);
  12. enableDestroy(server);
  13. var connected = 0;
  14. for (var i = 0; i < 10; i++) {
  15. var client = net.connect(1337);
  16. client.on('connect', function() {
  17. connected++;
  18. if (connected === 10) setTimeout(destroy);
  19. });
  20. // just ignore the resets
  21. client.on('error', function() {});
  22. }
  23. function destroy() {
  24. server.destroy(function() {
  25. console.log('ok');
  26. });
  27. }