diff --git a/client.js b/client.js index cd84eb3..79724da 100644 --- a/client.js +++ b/client.js @@ -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(); } diff --git a/server.js b/server.js index be089ac..9c754de 100644 --- a/server.js +++ b/server.js @@ -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; diff --git a/test-cluster.js b/test-cluster.js index d6b8ff7..5219fd3 100644 --- a/test-cluster.js +++ b/test-cluster.js @@ -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!'); + } + }); + }); }); }); });