Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Simplify arch check, style
  • Loading branch information
silverwind committed Apr 8, 2015
commit 30a1882785df1339c684895a57df4c0fc9216713
30 changes: 5 additions & 25 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

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

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

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

let cpuinfo;
if (process.config.variables.arm_version === '6')
return 6 * ms; // ARMv6

// arm version detection based on v8
try {
cpuinfo = fs.readFileSync('/proc/cpuinfo').toString();
} 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;
}
return 2 * ms; // ARMv7 and up.
};
Copy link
Copy Markdown
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
Copy Markdown
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,
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-wrap-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var server = tls.createServer(options, function(c) {

server.listen(common.PORT, function() {
var socket = net.connect(common.PORT, function() {
socket.setTimeout(common.platformTimeout(240), function () {
socket.setTimeout(common.platformTimeout(240), function() {
throw new Error('timeout');
});

Expand Down