nix Math.random(), force multicore test

This commit is contained in:
AJ ONeal 2015-12-03 05:39:08 +00:00
parent 51548bd534
commit 8e9dda61df
3 changed files with 22 additions and 7 deletions

View File

@ -23,7 +23,7 @@ function getConnection(opts) {
function retry() {
setTimeout(function () {
getConnection(opts).then(resolve, retry);
}, 100 + (Math.random() * 250));
}, 100 + (parseInt(require('crypto').randomBytes(2).toString('hex'), 16) % 250));
}
if (!opts.connect && ('ENOENT' === err.code || 'ECONNREFUSED' === err.code)) {
@ -126,7 +126,7 @@ function create(opts) {
if ('function' === typeof args[args.length - 1]) {
// TODO if off, search for cb and derive id from previous onMessage
id = Math.random();
id = require('crypto').randomBytes(16).toString('hex');
cb = args.pop();
}

View File

@ -64,7 +64,7 @@ function createApp(server, options) {
// you might use location.query.access_token to authenticate or share sessions
// or ws.upgradeReq.headers.cookie (see http://stackoverflow.com/a/16395220/151312
ws.__session_id = location.query.session_id || Math.random();
ws.__session_id = location.query.session_id || require('crypto').randomBytes(16).toString('hex');
ws.on('message', function (buffer) {
var cmd;

View File

@ -1,8 +1,8 @@
'use strict';
var cluster = require('cluster');
//var numCores = 2;
var numCores = require('os').cpus().length;
var numCores = 2;
//var numCores = require('os').cpus().length;
var id = (cluster.isMaster && '0' || cluster.worker.id).toString();
function run() {
@ -18,12 +18,27 @@ function run() {
store.get('baz', function (err, data) {
if (err) { console.error(err); return; }
console.log(id, 'should be null:', data);
if (null !== data) {
console.error(id, 'should be null:', data);
}
});
store.get('foo', function (err, data) {
if (err) { console.error(err); return; }
console.log(id, 'should be bar:', data);
if ('bar' !== data) {
console.error(id, 'should be bar:', data);
}
store.set('quux', { message: 'hey' }, function (/*err*/) {
store.get('quux', function (err, data) {
if (err) { console.error(err); return; }
if (!data || 'hey' !== data.message) {
console.error(id, "should be { message: 'hey' }:", data);
} else {
console.log('Are there any errors above? If not, we passed!');
}
});
});
});
});
});