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

test: increase timeouts on arm #1366

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var path = require('path');
var fs = require('fs');
var assert = require('assert');
Expand Down Expand Up @@ -179,6 +181,34 @@ exports.spawnPwd = function(options) {
}
};

const PLATFORM_TIMOUT_FACTORS = {
armv6: 6.0,
armv7: 2.0
};

exports.platformTimeout = function (ms) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style issue: function(ms)

if (process.arch !== 'arm')
return ms;

let cpuinfo;

// arm version detection based on v8
try {
cpuinfo = fs.readFileSync('/proc/cpuinfo').toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpuinfo = fs.readFileSync('/proc/cpuinfo', 'utf8') maybe?

} catch (e) {
return ms;
}

if (/\nCPU architecture:\s7\n/.test(cpuinfo)) {
return ms * PLATFORM_TIMOUT_FACTORS[/\(v6l\)/.test(cpuinfo) ?
'armv6' : 'armv7'];
} else if (/\nCPU architecture:\s6\n/.test(cpuinfo)) {
return ms * PLATFORM_TIMOUT_FACTORS['armv6'];
} else {
return ms;
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's an easier way:

exports.platformTimeout = function(ms) {
  if (process.platform !== 'arm')
    return ms;

  // arm_version is a stringified number or 'default'
  if (process.config.variables.arm_version === '6')
    return 6 * ms;  // ARMv6

  return 2 * ms;  // ARMv7 and up.
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's pretty convenient. Didn't know about these variables.


var knownGlobals = [setTimeout,
setInterval,
setImmediate,
Expand Down
11 changes: 7 additions & 4 deletions test/parallel/test-child-process-fork-net2.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ if (process.argv[2] === 'child') {

server.listen(common.PORT, '127.0.0.1');

var timeElasped = 0;
var timeElapsed = 0;
var closeServer = function() {
console.error('[m] closeServer');
var startTime = Date.now();
server.on('close', function() {
console.error('[m] emit(close)');
timeElasped = Date.now() - startTime;
timeElapsed = Date.now() - startTime;
});

console.error('[m] calling server.close');
Expand All @@ -149,11 +149,14 @@ if (process.argv[2] === 'child') {
}, 200);
};

var min = 190;
var max = common.platformTimeout(1500);
process.on('exit', function() {
assert.equal(disconnected, count);
assert.equal(connected, count);
assert.ok(closeEmitted);
assert.ok(timeElasped >= 190 && timeElasped <= 1000,
'timeElasped was not between 190 and 1000 ms');
assert.ok(timeElapsed >= min && timeElapsed <= max,
`timeElapsed was not between ${min} and ${max} ms:` +
`${timeElapsed}`);
});
}
2 changes: 1 addition & 1 deletion test/parallel/test-debug-signal-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function onNoMoreLines() {

setTimeout(function testTimedOut() {
assert(false, 'test timed out.');
}, 6000).unref();
}, common.platformTimeout(3000)).unref();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timeout seems to have been chosen too generous, so I reduced it.


process.on('exit', function onExit() {
// Kill processes in reverse order to avoid timing problems on Windows where
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-empty-readStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fs.open(emptyFile, 'r', function (error, fd) {

setTimeout(function () {
assert.equal(readEmit, true);
}, 50);
}, common.platformTimeout(50));
});

fs.open(emptyFile, 'r', function (error, fd) {
Expand All @@ -43,5 +43,5 @@ fs.open(emptyFile, 'r', function (error, fd) {

setTimeout(function () {
assert.equal(readEmit, false);
}, 50);
}, common.platformTimeout(50));
});
2 changes: 1 addition & 1 deletion test/parallel/test-http-end-throw-socket-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ server.listen(common.PORT, function() {
setTimeout(function() {
process.removeListener('uncaughtException', catcher);
throw new Error('Taking too long!');
}, 1000).unref();
}, common.platformTimeout(1000)).unref();

process.on('uncaughtException', catcher);
var errors = 0;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-timeout-throw.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ child.stdout.once('data', function() {
' });\n' +
'});"";\n');

setTimeout(child.stdin.end.bind(child.stdin), 200);
setTimeout(child.stdin.end.bind(child.stdin), common.platformTimeout(200));
}
});

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-fast-writing.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var gotDrain = false;
var timer = setTimeout(function() {
console.log('not ok - timed out');
process.exit(1);
}, 500);
}, common.platformTimeout(500));

function onconnection(conn) {
conn.on('data', function(c) {
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-tls-wrap-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ var server = tls.createServer(options, function(c) {

server.listen(common.PORT, function() {
var socket = net.connect(common.PORT, function() {
socket.setTimeout(240, assert.fail);
socket.setTimeout(common.platformTimeout(240), function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you undo the style change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test did show an error undefined undefined undefined, which I thought looked ugly. If that's prefered, I'll undo it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is the function () {. :-)

throw new Error('timeout');
});

var tsocket = tls.connect({
socket: socket,
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-force-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var cp = spawn(process.execPath, ['-i']);
var gotToEnd = false;
var timeoutId = setTimeout(function() {
throw new Error('timeout!');
}, 1000); // give node + the repl 1 second to boot up
}, common.platformTimeout(1000)); // give node + the repl 1 second to boot up

cp.stdout.setEncoding('utf8');

Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-net-GH-5504.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function parent() {
setTimeout(function() {
throw new Error('hang');
});
}, 4000).unref();
}, common.platformTimeout(2000)).unref();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.


var s = spawn(node, [__filename, 'server'], opt);
var c;
Expand Down