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:
Martti Malmi 2022-08-13 21:58:00 +03:00 committed by GitHub
parent d5c8a02980
commit 7123207c66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 253 additions and 50 deletions

View File

@ -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"){

View File

@ -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(){

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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(){

View File

@ -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(){

View File

@ -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();

View File

@ -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);
});

View File

@ -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){

View File

@ -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();
});
});
});
});