Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[patch] use high port random for test #15

Closed
bastien-roucaries opened this issue Jan 7, 2019 · 0 comments
Closed

[patch] use high port random for test #15

bastien-roucaries opened this issue Jan 7, 2019 · 0 comments

Comments

@bastien-roucaries
Copy link

bastien-roucaries commented Jan 7, 2019

Could you please apply this patch that improve testing robustness:

Subject: Use high port random for testing
Author: Bastien Roucariès <rouca@debian.org>

Avoid port collision by using high port

Forwarded: 

Index: node-timed-out/test.js
===================================================================
--- node-timed-out.orig/test.js
+++ node-timed-out/test.js
@@ -6,6 +6,7 @@ var assert = require('assert');
 var http = require('http');
 var net = require('net');
 var timeout = require('./');
+var port = Math.floor(Math.random() * (60000 - 30000) + 30000)
 
 /*
 it('should do HTTP request with a lot of time', function (done) {
@@ -40,7 +41,7 @@ describe('when connection is established
 
 	before(function (done) {
 		server = http.createServer();
-		server.listen(8081, done);
+		server.listen(port, done);
 	});
 
 	after(function (done) {
@@ -50,11 +51,11 @@ describe('when connection is established
 	it('should emit ESOCKETTIMEDOUT (no data)', function (done) {
 		server.once('request', function () {});
 
-		var req = http.get('http://0.0.0.0:8081');
+		var req = http.get('http://0.0.0.0:'+port);
 
 		req.on('error', function (err) {
 			if (err.code === 'ESOCKETTIMEDOUT') {
-				assert.equal(err.message, 'Socket timed out on request to 0.0.0.0:8081');
+				assert.equal(err.message, 'Socket timed out on request to 0.0.0.0:'+port);
 				done();
 			}
 		});
@@ -72,7 +73,7 @@ describe('when connection is established
 
 		var called = false;
 		var body = '';
-		var req = http.get('http://0.0.0.0:8081');
+		var req = http.get('http://0.0.0.0:'+port);
 
 		req.on('response', function (res) {
 			called = true;
@@ -88,7 +89,7 @@ describe('when connection is established
 			if (err.code === 'ESOCKETTIMEDOUT') {
 				assert.ok(called);
 				assert.equal(body, 'chunk');
-				assert.equal(err.message, 'Socket timed out on request to 0.0.0.0:8081');
+				assert.equal(err.message, 'Socket timed out on request to 0.0.0.0:'+port);
 				done();
 			}
 		});
@@ -104,7 +105,7 @@ describe('when connection is established
 			}, 100);
 		});
 
-		var req = http.get('http://0.0.0.0:8081');
+		var req = http.get('http://0.0.0.0:'+port);
 
 		req.on('error', done);
 		req.on('finish', done);
@@ -120,11 +121,11 @@ describe('when connection is established
 			}, 200);
 		});
 
-		var req = http.get('http://0.0.0.0:8081');
+		var req = http.get('http://0.0.0.0:'+port);
 
 		req.on('error', function (err) {
 			if (err.code === 'ESOCKETTIMEDOUT') {
-				assert.equal(err.message, 'Socket timed out on request to 0.0.0.0:8081');
+				assert.equal(err.message, 'Socket timed out on request to 0.0.0.0:'+port);
 				done();
 			}
 		});
@@ -147,7 +148,7 @@ describe('when connection is established
 
 		var reqOpts = {
 			hostname: '0.0.0.0',
-			port: 8081,
+			port: port,
 			agent: keepAliveAgent
 		};
 
@@ -176,13 +177,13 @@ describe('when connection is established
 	it('should set socket timeout if socket is already connected', function (done) {
 		server.once('request', function () {});
 
-		var socket = net.connect(8081, '0.0.0.0', function () {
+		var socket = net.connect(port, '0.0.0.0', function () {
 			var req = http.get({
 				createConnection: function () {
 					return socket;
 				},
 				hostname: '0.0.0.0',
-				port: 8081
+				port: port
 			});
 
 			req.on('error', function (err) {
@@ -210,7 +211,7 @@ describe('when connection is established
 		var options = {
 			hostname: '0.0.0.0',
 			agent: agent,
-			port: 8081
+			port: port
 		};
 
 		var req = http.get(options, function (res) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant