revise installing a license file
[platform/upstream/nodejs.git] / test / parallel / test-net-error-twice.js
1 'use strict';
2 const common = require('../common');
3 const assert = require('assert');
4 const net = require('net');
5
6 const buf = new Buffer(10 * 1024 * 1024);
7
8 buf.fill(0x62);
9
10 const errs = [];
11 var clientSocket;
12 var serverSocket;
13
14 function ready() {
15   if (clientSocket && serverSocket) {
16     clientSocket.destroy();
17     serverSocket.write(buf);
18   }
19 }
20
21 var srv = net.createServer(function onConnection(conn) {
22   conn.on('error', function(err) {
23     errs.push(err);
24     if (errs.length > 1 && errs[0] === errs[1])
25       assert(false, 'We should not be emitting the same error twice');
26   });
27   conn.on('close', function() {
28     srv.unref();
29   });
30   serverSocket = conn;
31   ready();
32 }).listen(common.PORT, function() {
33   var client = net.connect({ port: common.PORT });
34
35   client.on('connect', function() {
36     clientSocket = client;
37     ready();
38   });
39 });
40
41 process.on('exit', function() {
42   console.log(errs);
43   assert.equal(errs.length, 1);
44 });