mirror of
https://github.com/amark/gun.git
synced 2025-06-07 14:46:44 +00:00
Panic tests for rod & radix.js try / catch (#1269)
* try/catch radix.js * rod test/panic/chat.js rod test/panic/holy-grail.js rod panic tests
This commit is contained in:
parent
d5c8a02980
commit
7123207c66
79
lib/radix.js
79
lib/radix.js
@ -62,47 +62,50 @@
|
|||||||
return radix;
|
return radix;
|
||||||
};
|
};
|
||||||
|
|
||||||
Radix.map = function rap(radix, cb, opt, pre){ pre = pre || []; // TODO: BUG: most out-of-memory crashes come from here.
|
Radix.map = function rap(radix, cb, opt, pre){
|
||||||
var t = ('function' == typeof radix)? radix.$ || {} : radix;
|
try {
|
||||||
//!opt && console.log("WHAT IS T?", JSON.stringify(t).length);
|
pre = pre || []; // TODO: BUG: most out-of-memory crashes come from here.
|
||||||
if(!t){ return }
|
var t = ('function' == typeof radix)? radix.$ || {} : radix;
|
||||||
if('string' == typeof t){ if(Radix.debug){ throw ['BUG:', radix, cb, opt, pre] } return; }
|
//!opt && console.log("WHAT IS T?", JSON.stringify(t).length);
|
||||||
var keys = (t[_]||no).sort || (t[_] = function $(){ $.sort = Object.keys(t).sort(); return $ }()).sort, rev; // ONLY 17% of ops are pre-sorted!
|
if(!t){ return }
|
||||||
//var keys = Object.keys(t).sort();
|
if('string' == typeof t){ if(Radix.debug){ throw ['BUG:', radix, cb, opt, pre] } return; }
|
||||||
opt = (true === opt)? {branch: true} : (opt || {});
|
var keys = (t[_]||no).sort || (t[_] = function $(){ $.sort = Object.keys(t).sort(); return $ }()).sort, rev; // ONLY 17% of ops are pre-sorted!
|
||||||
if(rev = opt.reverse){ keys = keys.slice(0).reverse() }
|
//var keys = Object.keys(t).sort();
|
||||||
var start = opt.start, end = opt.end, END = '\uffff';
|
opt = (true === opt)? {branch: true} : (opt || {});
|
||||||
var i = 0, l = keys.length;
|
if(rev = opt.reverse){ keys = keys.slice(0).reverse() }
|
||||||
for(;i < l; i++){ var key = keys[i], tree = t[key], tmp, p, pt;
|
var start = opt.start, end = opt.end, END = '\uffff';
|
||||||
if(!tree || '' === key || _ === key || 'undefined' === key){ continue }
|
var i = 0, l = keys.length;
|
||||||
p = pre.slice(0); p.push(key);
|
for(;i < l; i++){ var key = keys[i], tree = t[key], tmp, p, pt;
|
||||||
pt = p.join('');
|
if(!tree || '' === key || _ === key || 'undefined' === key){ continue }
|
||||||
if(u !== start && pt < (start||'').slice(0,pt.length)){ continue }
|
p = pre.slice(0); p.push(key);
|
||||||
if(u !== end && (end || END) < pt){ continue }
|
pt = p.join('');
|
||||||
if(rev){ // children must be checked first when going in reverse.
|
if(u !== start && pt < (start||'').slice(0,pt.length)){ continue }
|
||||||
tmp = rap(tree, cb, opt, p);
|
if(u !== end && (end || END) < pt){ continue }
|
||||||
if(u !== tmp){ return tmp }
|
if(rev){ // children must be checked first when going in reverse.
|
||||||
}
|
tmp = rap(tree, cb, opt, p);
|
||||||
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 }
|
if(u !== tmp){ return tmp }
|
||||||
}
|
}
|
||||||
} else
|
if(u !== (tmp = tree[''])){
|
||||||
if(opt.branch){
|
var yes = 1;
|
||||||
tmp = cb(u, pt, key, pre);
|
if(u !== start && pt < (start||'')){ yes = 0 }
|
||||||
if(u !== tmp){ return tmp }
|
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;
|
} catch (e) { console.error(e); }
|
||||||
if(!rev){
|
|
||||||
tmp = rap(tree, cb, opt, pre);
|
|
||||||
if(u !== tmp){ return tmp }
|
|
||||||
}
|
|
||||||
pre.pop();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if(typeof window !== "undefined"){
|
if(typeof window !== "undefined"){
|
||||||
|
@ -85,6 +85,21 @@ describe("Put ACK", function(){
|
|||||||
peers.push('http://'+ env.config.IP + ':' + tmp + '/gun');
|
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);
|
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.
|
var gun = Gun({file: env.i+'data', peers: peers, web: server, axe: false}); // Note: test with AXE on & off.
|
||||||
server.listen(port, function(){
|
server.listen(port, function(){
|
||||||
|
@ -78,6 +78,24 @@ describe("GET GET", function(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(port, " connect to ", peers);
|
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});
|
var gun = Gun({file: env.i+'data', peers: peers, web: server});
|
||||||
server.listen(port, function(){
|
server.listen(port, function(){
|
||||||
test.done();
|
test.done();
|
||||||
|
@ -74,6 +74,24 @@ describe("Put ACK", function(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(port, " connect to ", peers);
|
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});
|
var gun = Gun({file: false, rad: false, localStorage: false, file: env.i+'data', peers: peers, web: server, axe: false});
|
||||||
server.listen(port, function(){
|
server.listen(port, function(){
|
||||||
test.done();
|
test.done();
|
||||||
|
@ -86,6 +86,24 @@ describe("Dedup load balancing GETs", function(){
|
|||||||
peers.push('http://'+ env.config.IP + ':' + tmp + '/gun');
|
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});
|
var gun = Gun({peers: peers, web: server, rad: false, radisk: false, file: false, localStorage: false, axe: false});
|
||||||
server.listen(port, function(){
|
server.listen(port, function(){
|
||||||
test.done();
|
test.done();
|
||||||
|
@ -59,6 +59,24 @@ describe("Do not connect to self", function(){
|
|||||||
// make sure to connect to self/same.
|
// make sure to connect to self/same.
|
||||||
peers.push(self_url);
|
peers.push(self_url);
|
||||||
console.log(port, " connect to ", peers);
|
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});
|
var gun = Gun({file: env.i+'data', peers: peers, web: server, multicast: false});
|
||||||
global.gun = gun;
|
global.gun = gun;
|
||||||
server.listen(port, function(){
|
server.listen(port, function(){
|
||||||
|
@ -65,6 +65,24 @@ describe("Put ACK", function(){
|
|||||||
}
|
}
|
||||||
global.peerID = String.fromCharCode(64 + env.i);
|
global.peerID = String.fromCharCode(64 + env.i);
|
||||||
console.log(env.i, port, " connect to ", peers);
|
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});
|
var gun = Gun({file: env.i+'data', pid: peerID, peers: peers, web: server});
|
||||||
global.gun = gun;
|
global.gun = gun;
|
||||||
server.listen(port, function(){
|
server.listen(port, function(){
|
||||||
|
@ -78,6 +78,24 @@ describe("Dedup load balancing GETs", function(){
|
|||||||
var tmp = (env.config.port + (i + 1));
|
var tmp = (env.config.port + (i + 1));
|
||||||
peers.push('http://'+ env.config.IP + ':' + tmp + '/gun');
|
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});
|
var gun = Gun({file: env.i+'data', peers: peers, web: server});
|
||||||
server.listen(port, function(){
|
server.listen(port, function(){
|
||||||
test.done();
|
test.done();
|
||||||
|
@ -86,19 +86,50 @@ describe("Mob test.", function(){
|
|||||||
relays.each(function(client){
|
relays.each(function(client){
|
||||||
tests.push(client.run(function(test){
|
tests.push(client.run(function(test){
|
||||||
var env = test.props;
|
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 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;
|
var peers = [], i = env.config.relays;
|
||||||
while(i--){ // make sure to connect to self/same.
|
while(i--){ // make sure to connect to self/same.
|
||||||
var tmp = (env.config.port + (i + 1));
|
var tmp = (env.config.port + (i + 1));
|
||||||
peers.push('http://'+ env.config.IP + ':' + tmp + '/gun');
|
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);
|
console.log(port, " connect to ", peers);
|
||||||
var gun = Gun({file: env.i+'data', peers: peers, web: server, mob: 3, multicast: false});
|
var gun = Gun({file: env.i+'data', peers: peers, web: server, mob: 3, multicast: false});
|
||||||
global.gun = gun;
|
global.gun = gun;
|
||||||
|
@ -84,6 +84,22 @@ describe("Load test "+ config.browsers +" browser(s) across "+ config.relays +"
|
|||||||
var env = test.props;
|
var env = test.props;
|
||||||
// As a result, we have to manually pass it scope.
|
// As a result, we have to manually pass it scope.
|
||||||
test.async();
|
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.
|
// Clean up from previous test.
|
||||||
try{ require('fs').unlinkSync(env.i+'data.json') }catch(e){}
|
try{ require('fs').unlinkSync(env.i+'data.json') }catch(e){}
|
||||||
var server = require('http').createServer(function(req, res){
|
var server = require('http').createServer(function(req, res){
|
||||||
|
@ -51,12 +51,26 @@ describe("The Holy Grail Test!", function(){
|
|||||||
it("GUN started!", function(){
|
it("GUN started!", function(){
|
||||||
return relay.run(function(test){
|
return relay.run(function(test){
|
||||||
var env = test.props;
|
var env = test.props;
|
||||||
|
var port = env.config.port + env.i;
|
||||||
test.async();
|
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+'data') }catch(e){}
|
||||||
try{ require('fs').unlinkSync((env.i+1)+'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+'data') }catch(e){}
|
||||||
try{ require('gun/lib/fsrm')((env.i+1)+'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){
|
var server = require('http').createServer(function(req, res){
|
||||||
res.end("I am "+ env.i +"!");
|
res.end("I am "+ env.i +"!");
|
||||||
});
|
});
|
||||||
@ -186,10 +200,25 @@ describe("The Holy Grail Test!", function(){
|
|||||||
it("GUN spawned!", function(){
|
it("GUN spawned!", function(){
|
||||||
return spawn.run(function(test){
|
return spawn.run(function(test){
|
||||||
var env = test.props;
|
var env = test.props;
|
||||||
|
var port = env.config.port + env.i;
|
||||||
test.async();
|
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+'data') }catch(e){}
|
||||||
try{ require('gun/lib/fsrm')(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){
|
var server = require('http').createServer(function(req, res){
|
||||||
res.end("I am "+ env.i +"!");
|
res.end("I am "+ env.i +"!");
|
||||||
});
|
});
|
||||||
@ -287,3 +316,4 @@ describe("The Holy Grail Test!", function(){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user