diff --git a/lib/radix.js b/lib/radix.js index 62fa85bf..e60789e4 100644 --- a/lib/radix.js +++ b/lib/radix.js @@ -62,47 +62,50 @@ return radix; }; - Radix.map = function rap(radix, cb, opt, pre){ pre = pre || []; // TODO: BUG: most out-of-memory crashes come from here. - var t = ('function' == typeof radix)? radix.$ || {} : radix; - //!opt && console.log("WHAT IS T?", JSON.stringify(t).length); - if(!t){ return } - if('string' == typeof t){ if(Radix.debug){ throw ['BUG:', radix, cb, opt, pre] } return; } - var keys = (t[_]||no).sort || (t[_] = function $(){ $.sort = Object.keys(t).sort(); return $ }()).sort, rev; // ONLY 17% of ops are pre-sorted! - //var keys = Object.keys(t).sort(); - opt = (true === opt)? {branch: true} : (opt || {}); - if(rev = opt.reverse){ keys = keys.slice(0).reverse() } - var start = opt.start, end = opt.end, END = '\uffff'; - var i = 0, l = keys.length; - for(;i < l; i++){ var key = keys[i], tree = t[key], tmp, p, pt; - if(!tree || '' === key || _ === key || 'undefined' === key){ continue } - p = pre.slice(0); p.push(key); - pt = p.join(''); - if(u !== start && pt < (start||'').slice(0,pt.length)){ continue } - if(u !== end && (end || END) < pt){ continue } - if(rev){ // children must be checked first when going in reverse. - tmp = rap(tree, cb, opt, p); - if(u !== tmp){ return tmp } - } - if(u !== (tmp = tree[''])){ - var yes = 1; - if(u !== start && pt < (start||'')){ yes = 0 } - if(u !== end && pt > (end || END)){ yes = 0 } - if(yes){ - tmp = cb(tmp, pt, key, pre); + Radix.map = function rap(radix, cb, opt, pre){ + try { + pre = pre || []; // TODO: BUG: most out-of-memory crashes come from here. + var t = ('function' == typeof radix)? radix.$ || {} : radix; + //!opt && console.log("WHAT IS T?", JSON.stringify(t).length); + if(!t){ return } + if('string' == typeof t){ if(Radix.debug){ throw ['BUG:', radix, cb, opt, pre] } return; } + var keys = (t[_]||no).sort || (t[_] = function $(){ $.sort = Object.keys(t).sort(); return $ }()).sort, rev; // ONLY 17% of ops are pre-sorted! + //var keys = Object.keys(t).sort(); + opt = (true === opt)? {branch: true} : (opt || {}); + if(rev = opt.reverse){ keys = keys.slice(0).reverse() } + var start = opt.start, end = opt.end, END = '\uffff'; + var i = 0, l = keys.length; + for(;i < l; i++){ var key = keys[i], tree = t[key], tmp, p, pt; + if(!tree || '' === key || _ === key || 'undefined' === key){ continue } + p = pre.slice(0); p.push(key); + pt = p.join(''); + if(u !== start && pt < (start||'').slice(0,pt.length)){ continue } + if(u !== end && (end || END) < pt){ continue } + if(rev){ // children must be checked first when going in reverse. + tmp = rap(tree, cb, opt, p); if(u !== tmp){ return tmp } } - } else - if(opt.branch){ - tmp = cb(u, pt, key, pre); - if(u !== tmp){ return tmp } + if(u !== (tmp = tree[''])){ + var yes = 1; + if(u !== start && pt < (start||'')){ yes = 0 } + if(u !== end && pt > (end || END)){ yes = 0 } + if(yes){ + tmp = cb(tmp, pt, key, pre); + if(u !== tmp){ return tmp } + } + } else + if(opt.branch){ + tmp = cb(u, pt, key, pre); + if(u !== tmp){ return tmp } + } + pre = p; + if(!rev){ + tmp = rap(tree, cb, opt, pre); + if(u !== tmp){ return tmp } + } + pre.pop(); } - pre = p; - if(!rev){ - tmp = rap(tree, cb, opt, pre); - if(u !== tmp){ return tmp } - } - pre.pop(); - } + } catch (e) { console.error(e); } }; if(typeof window !== "undefined"){ diff --git a/test/panic/1putackget.js b/test/panic/1putackget.js index bddfe592..b8e19fb0 100644 --- a/test/panic/1putackget.js +++ b/test/panic/1putackget.js @@ -85,6 +85,21 @@ describe("Put ACK", function(){ peers.push('http://'+ env.config.IP + ':' + tmp + '/gun'); } } + + if (process.env.ROD_PATH) { + // currently fails because rod doesn't ack + console.log('testing with rod'); + const sp = require('child_process').spawn(process.env.ROD_PATH, ['start', '--port', port, '--sled-storage=false', '--peers', peers.join(',').replaceAll('http', 'ws')]); + sp.stdout.on('data', function(data){ + console.log(data.toString()); + }); + sp.stderr.on('data', function(data){ + console.log(data.toString()); + }); + test.done(); + return; + } + console.log(port, " connect to ", peers); var gun = Gun({file: env.i+'data', peers: peers, web: server, axe: false}); // Note: test with AXE on & off. server.listen(port, function(){ diff --git a/test/panic/2getget.js b/test/panic/2getget.js index 1d3e20df..e61518c2 100644 --- a/test/panic/2getget.js +++ b/test/panic/2getget.js @@ -78,6 +78,24 @@ describe("GET GET", function(){ } } console.log(port, " connect to ", peers); + + if (process.env.ROD_PATH) { + console.log('testing with rod'); + var args = ['start', '--port', port, '--sled-storage=false']; + if (peers.length) { + args.push('--peers=' + peers.join(',').replaceAll('http', 'ws')); + } + const sp = require('child_process').spawn(process.env.ROD_PATH, args); + sp.stdout.on('data', function(data){ + console.log(data.toString()); + }); + sp.stderr.on('data', function(data){ + console.log(data.toString()); + }); + test.done(); + return; + } + var gun = Gun({file: env.i+'data', peers: peers, web: server}); server.listen(port, function(){ test.done(); diff --git a/test/panic/3puts.js b/test/panic/3puts.js index 8d9b777f..e3d70a0b 100644 --- a/test/panic/3puts.js +++ b/test/panic/3puts.js @@ -74,6 +74,24 @@ describe("Put ACK", function(){ } } console.log(port, " connect to ", peers); + + if (process.env.ROD_PATH) { + console.log('testing with rod'); + var args = ['start', '--port', port, '--sled-storage=false']; + if (peers.length) { + args.push('--peers=' + peers.join(',').replaceAll('http', 'ws')); + } + const sp = require('child_process').spawn(process.env.ROD_PATH, args); + sp.stdout.on('data', function(data){ + console.log(data.toString()); + }); + sp.stderr.on('data', function(data){ + console.log(data.toString()); + }); + test.done(); + return; + } + var gun = Gun({file: false, rad: false, localStorage: false, file: env.i+'data', peers: peers, web: server, axe: false}); server.listen(port, function(){ test.done(); diff --git a/test/panic/4putackdedup.js b/test/panic/4putackdedup.js index b0017d4e..2ce65823 100644 --- a/test/panic/4putackdedup.js +++ b/test/panic/4putackdedup.js @@ -86,6 +86,24 @@ describe("Dedup load balancing GETs", function(){ peers.push('http://'+ env.config.IP + ':' + tmp + '/gun'); } } + + if (process.env.ROD_PATH) { + console.log('testing with rod'); + var args = ['start', '--port', port, '--sled-storage=false']; + if (peers.length) { + args.push('--peers=' + peers.join(',').replaceAll('http', 'ws')); + } + const sp = require('child_process').spawn(process.env.ROD_PATH, args); + sp.stdout.on('data', function(data){ + console.log(data.toString()); + }); + sp.stderr.on('data', function(data){ + console.log(data.toString()); + }); + test.done(); + return; + } + var gun = Gun({peers: peers, web: server, rad: false, radisk: false, file: false, localStorage: false, axe: false}); server.listen(port, function(){ test.done(); diff --git a/test/panic/axe/1no_self.js b/test/panic/axe/1no_self.js index 5b6ad38f..e4e30cf4 100644 --- a/test/panic/axe/1no_self.js +++ b/test/panic/axe/1no_self.js @@ -59,6 +59,24 @@ describe("Do not connect to self", function(){ // make sure to connect to self/same. peers.push(self_url); console.log(port, " connect to ", peers); + + if (process.env.ROD_PATH) { + console.log('testing with rod'); + var args = ['start', '--port', port, '--sled-storage=false']; + if (peers.length) { + args.push('--peers=' + peers.join(',').replaceAll('http', 'ws')); + } + const sp = require('child_process').spawn(process.env.ROD_PATH, args); + sp.stdout.on('data', function(data){ + console.log(data.toString()); + }); + sp.stderr.on('data', function(data){ + console.log(data.toString()); + }); + test.done(); + return; + } + var gun = Gun({file: env.i+'data', peers: peers, web: server, multicast: false}); global.gun = gun; server.listen(port, function(){ diff --git a/test/panic/axe/2no_dup.js b/test/panic/axe/2no_dup.js index c7bd9d7f..21cd27dc 100644 --- a/test/panic/axe/2no_dup.js +++ b/test/panic/axe/2no_dup.js @@ -65,6 +65,24 @@ describe("Put ACK", function(){ } global.peerID = String.fromCharCode(64 + env.i); console.log(env.i, port, " connect to ", peers); + + if (process.env.ROD_PATH) { + console.log('testing with rod'); + var args = ['start', '--port', port, '--sled-storage=false']; + if (peers.length) { + args.push('--peers=' + peers.join(',').replaceAll('http', 'ws')); + } + const sp = require('child_process').spawn(process.env.ROD_PATH, args); + sp.stdout.on('data', function(data){ + console.log(data.toString()); + }); + sp.stderr.on('data', function(data){ + console.log(data.toString()); + }); + test.done(); + return; + } + // TODO what should gun be when testing on rod? var gun = Gun({file: env.i+'data', pid: peerID, peers: peers, web: server}); global.gun = gun; server.listen(port, function(){ diff --git a/test/panic/axe/3get_turns.js b/test/panic/axe/3get_turns.js index e003803b..3d840c87 100644 --- a/test/panic/axe/3get_turns.js +++ b/test/panic/axe/3get_turns.js @@ -78,6 +78,24 @@ describe("Dedup load balancing GETs", function(){ var tmp = (env.config.port + (i + 1)); peers.push('http://'+ env.config.IP + ':' + tmp + '/gun'); } + + if (process.env.ROD_PATH) { + console.log('testing with rod'); + var args = ['start', '--port', port, '--sled-storage=false']; + if (peers.length) { + args.push('--peers=' + peers.join(',').replaceAll('http', 'ws')); + } + const sp = require('child_process').spawn(process.env.ROD_PATH, args); + sp.stdout.on('data', function(data){ + console.log(data.toString()); + }); + sp.stderr.on('data', function(data){ + console.log(data.toString()); + }); + test.done(); + return; + } + var gun = Gun({file: env.i+'data', peers: peers, web: server}); server.listen(port, function(){ test.done(); diff --git a/test/panic/axe/4mob.js b/test/panic/axe/4mob.js index 5e5406ab..05e3662a 100644 --- a/test/panic/axe/4mob.js +++ b/test/panic/axe/4mob.js @@ -86,19 +86,50 @@ describe("Mob test.", function(){ relays.each(function(client){ tests.push(client.run(function(test){ var env = test.props; - test.async(); - try{ require('fs').unlinkSync(env.i+'data') }catch(e){} - try{ require('gun/lib/fsrm')(env.i+'data') }catch(e){} - var server = require('http').createServer(function(req, res){ - res.end("I am "+ env.i +"!"); - }); var port = env.config.port + env.i; - var Gun; try{ Gun = require('gun') }catch(e){ console.log("GUN not found! You need to link GUN to PANIC. Nesting the `gun` repo inside a `node_modules` parent folder often fixes this.") } + test.async(); + var peers = [], i = env.config.relays; while(i--){ // make sure to connect to self/same. var tmp = (env.config.port + (i + 1)); peers.push('http://'+ env.config.IP + ':' + tmp + '/gun'); } + + if (process.env.ROD_PATH) { + console.log('testing with rod'); + var args = ['start', '--port', port, '--sled-storage=false']; + if (peers.length) { + args.push('--peers=' + peers.join(',').replaceAll('http', 'ws')); + } + const sp = require('child_process').spawn(process.env.ROD_PATH, args); + sp.stdout.on('data', function(data){ + console.log(data.toString()); + }); + sp.stderr.on('data', function(data){ + console.log(data.toString()); + }); + test.done(); + return; + } + + try { + require('fs').unlinkSync(env.i + 'data') + } catch (e) { + } + try { + require('gun/lib/fsrm')(env.i + 'data') + } catch (e) { + } + var server = require('http').createServer(function (req, res) { + res.end("I am " + env.i + "!"); + }); + var Gun; + try { + Gun = require('gun') + } catch (e) { + console.log("GUN not found! You need to link GUN to PANIC. Nesting the `gun` repo inside a `node_modules` parent folder often fixes this.") + } + console.log(port, " connect to ", peers); var gun = Gun({file: env.i+'data', peers: peers, web: server, mob: 3, multicast: false}); global.gun = gun; @@ -107,7 +138,7 @@ describe("Mob test.", function(){ }); gun.get('a').on(function(){ }); // TODO: Wrong! This is an example of the test using GUN in weird ways to work around bugs at the time of writing. This line should not be necessary, AXE should still pass even if this line is commented out, however if it fails then that is a bug in GUN's logic, not AXE. - }, {i: i += 1, config: config})); + }, {i: i += 1, config: config})); }); return Promise.all(tests); }); @@ -151,7 +182,7 @@ describe("Mob test.", function(){ test.done(); } gun.TO = setTimeout(end, 3000); - }, {i: i += 1, config: config})); + }, {i: i += 1, config: config})); }); return Promise.all(tests); }); diff --git a/test/panic/chat.js b/test/panic/chat.js index 06ff82bc..5387bba5 100644 --- a/test/panic/chat.js +++ b/test/panic/chat.js @@ -84,6 +84,22 @@ describe("Load test "+ config.browsers +" browser(s) across "+ config.relays +" var env = test.props; // As a result, we have to manually pass it scope. test.async(); + if (process.env.ROD_PATH) { + try { + const sp = require('child_process').spawn(process.env.ROD_PATH, ['start', '--port', env.config.port + env.i, '--sled-storage=false']); + sp.stdout.on('data', function(data){ + console.log(data.toString()); + }); + sp.stderr.on('data', function(data){ + console.log(data.toString()); + }); + test.done(); + } catch (e) { + console.log(e); + } + return; + } + // Clean up from previous test. try{ require('fs').unlinkSync(env.i+'data.json') }catch(e){} var server = require('http').createServer(function(req, res){ diff --git a/test/panic/holy-grail.js b/test/panic/holy-grail.js index affd3876..949093da 100644 --- a/test/panic/holy-grail.js +++ b/test/panic/holy-grail.js @@ -51,12 +51,26 @@ describe("The Holy Grail Test!", function(){ it("GUN started!", function(){ return relay.run(function(test){ var env = test.props; + var port = env.config.port + env.i; test.async(); + + if (process.env.ROD_PATH) { + console.log('testing with rod'); + const sp = require('child_process').spawn(process.env.ROD_PATH, ['start', '--port', port, '--sled-storage=false']); + sp.stdout.on('data', function(data){ + console.log(data.toString()); + }); + sp.stderr.on('data', function(data){ + console.log(data.toString()); + }); + test.done(); + return; + } + try{ require('fs').unlinkSync(env.i+'data') }catch(e){} try{ require('fs').unlinkSync((env.i+1)+'data') }catch(e){} try{ require('gun/lib/fsrm')(env.i+'data') }catch(e){} try{ require('gun/lib/fsrm')((env.i+1)+'data') }catch(e){} - var port = env.config.port + env.i; var server = require('http').createServer(function(req, res){ res.end("I am "+ env.i +"!"); }); @@ -186,10 +200,25 @@ describe("The Holy Grail Test!", function(){ it("GUN spawned!", function(){ return spawn.run(function(test){ var env = test.props; + var port = env.config.port + env.i; test.async(); + + if (process.env.ROD_PATH) { + console.log('testing with rod'); + const sp = require('child_process').spawn(process.env.ROD_PATH, ['start', '--port', port, '--sled-storage=false']); + sp.stdout.on('data', function(data){ + console.log(data.toString()); + }); + sp.stderr.on('data', function(data){ + console.log(data.toString()); + }); + test.done(); + return; + } + + try{ require('fs').unlinkSync(env.i+'data') }catch(e){} try{ require('gun/lib/fsrm')(env.i+'data') }catch(e){} - var port = env.config.port + env.i; var server = require('http').createServer(function(req, res){ res.end("I am "+ env.i +"!"); }); @@ -286,4 +315,5 @@ describe("The Holy Grail Test!", function(){ process.exit(); }); }); -}); \ No newline at end of file +}); +