update on-recovery PANIC test to run default & radisk configurations (#1078)

This commit is contained in:
nsreed 2021-06-16 14:56:34 -04:00 committed by GitHub
parent fc10c250c9
commit 10b42525ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,9 @@
// visible/active throughout the tests, because an inactive tab will NOT
// reconnect to the relay peer until the tab is active again. (Chrome 83)
// Uses a pattern described in https://stackoverflow.com/a/39286581/13564512
// to run multiple configurations of a mocha test.
var config = {
IP: require('ip').address(),
port: 8765,
@ -16,18 +19,63 @@ var config = {
route: {
'/': __dirname + '/index.html',
'/gun.js': __dirname + '/../../gun.js',
'/jquery.js': __dirname + '/../../examples/jquery.js'
'/jquery.js': __dirname + '/../../examples/jquery.js',
'/radix.js': __dirname + '/../../lib/radix.js',
'/radisk.js': __dirname + '/../../lib/radisk.js',
'/store.js': __dirname + '/../../lib/store.js',
'/rindexed.js': __dirname + '/../../lib/rindexed.js'
},
/** Test variants to run */
variants: ['default', 'radisk'],
/** Configuration details for each variant. If unspecified, variant will run with no additional configuration. */
variantConfigs: {
radisk: {
/** Options to pass the Gun constructor */
opts: {
localStorage: false
},
/** Libraries to import before constructing Gun */
imports: [
'radix.js',
'radisk.js',
'store.js',
'rindexed.js'
]
}
}
};
var {loadBrowserScripts} = require('./util/load-browser-scripts');
var panic = require('panic-server');
panic.server().on('request', function (req, res) {
config.route[req.url] && require('fs').createReadStream(config.route[req.url]).pipe(res);
}).listen(config.port);
var clients = panic.clients;
var manager = require('panic-manager')();
var clients = panic.clients;
var servers = clients.filter('Node.js');
/** The first relay peer */
var bob = servers.pluck(1);
/** The second relay peer */
var carl = servers.excluding(bob).pluck(1);
var browsers = clients.excluding(servers);
/** The "sending" browser */
var alice = browsers.pluck(1);
/** The "receiving" browser */
var dave = browsers.excluding(alice).pluck(1);
// Describe the test itself
describe("gun.on should receive updates after crashed relay peer comes back online", function () {
this.timeout(10 * 1000);
config.variants.forEach((variant) => {
var variantConfig = config.variantConfigs[variant] || {};
// Describe the variant
describe(`with ${variant} plugin configuration`, function () {
before('PANIC manager setup servers', function () {
// we are terminating the gun servers after each test variant, so we need to start them up again before each test variant
manager.start({
clients: Array(config.servers).fill().map(function (u, i) {
return {
@ -37,18 +85,9 @@ manager.start({
}),
panic: 'http://' + config.IP + ':' + config.port
});
});
var servers = clients.filter('Node.js');
var bob = servers.pluck(1);
var carl = servers.excluding(bob).pluck(1);
var browsers = clients.excluding(servers);
var alice = browsers.pluck(1);
var dave = browsers.excluding(alice).pluck(1);
describe("gun.on should receive updates after crashed relay peer comes back online", function(){
this.timeout(10 * 60 * 1000);
it("Servers have joined!", function(){
before("Servers have joined!", function () {
return servers.atLeast(config.servers);
});
@ -72,10 +111,16 @@ describe("gun.on should receive updates after crashed relay peer comes back onli
});
it(config.browsers + " browser(s) have joined!", function () {
require('./util/open').web(config.browsers, "http://"+ config.IP +":"+ config.port);
require('./util/open').web(config.browsers, "http://" + config.IP + ":" + config.port, {
headless: true,
});
return browsers.atLeast(config.browsers);
});
it(`Browsers loaded ${variant} plugin libraries`, function () {
return loadBrowserScripts(browsers, variantConfig.imports);
});
it("Browsers initialized gun!", function () {
var tests = [], i = 0;
browsers.each(function (client, id) {
@ -83,9 +128,16 @@ describe("gun.on should receive updates after crashed relay peer comes back onli
try {localStorage.clear()} catch (e) { }
try {indexedDB.deleteDatabase('radata')} catch (e) { }
var env = test.props;
var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
var configOpts = env.variantConfig.opts || {};
var opts = {
peers: ['http://' + env.config.IP + ':' + (env.config.port + 1) + '/gun'],
...configOpts
};
console.log('using constructor options: ', JSON.stringify(opts));
var gun = Gun(opts);
window.ref = gun.get('a');
}, {i: i += 1, config: config}));
}, {i: i += 1, config: config, variantConfig: variantConfig}));
});
return Promise.all(tests);
});
@ -95,7 +147,7 @@ describe("gun.on should receive updates after crashed relay peer comes back onli
console.log("I AM DAVE");
test.async();
ref.on(function (data) {
console.log("Just received data: ", data);
console.log("Just received data: ", JSON.stringify(data));
if (data.hello === 'world') {window.receivedFirst = true;}
if (data.foo === 'bar') {window.receivedSecond = true;}
});
@ -110,6 +162,9 @@ describe("gun.on should receive updates after crashed relay peer comes back onli
ref.put({hello: 'world'}, function (ack) {
if (!ack.err) {
test.done();
} else {
console.log('ALICE WAS UNABLE TO PUT DATA!');
test.fail();
}
});
});
@ -216,9 +271,17 @@ describe("gun.on should receive updates after crashed relay peer comes back onli
});
});
after("Everything shut down.", function(){
return require('./util/open').cleanup() || bob.run(function(){
it('Closed browsers & servers', function () {
var promises = [];
promises.push(bob.run(function () {
process.exit();
}));
promises.push(carl.run(function () {
process.exit();
}));
promises.push(require('./util/open').cleanup());
return Promise.all(promises);
});
});
});
});