mirror of
https://github.com/gundb/panic-server.git
synced 2026-05-07 03:00:26 -04:00
You can now boot up tests from the homepage using the UI. It's powered by jQuery. The tests are now using the latest, greatest version of gun, v0.3. Files now organized into folder "lib" for clarity and cleanliness. Numerous code cleanliness improvements. Now, if errors are passed to the acknowledgement listener, they're pushed to an array of errors on that request. Now each time there's a response, the statistics are recalculated and are passed to an optional progress callback. Patch.js now has stronger type checking against the data it's been given. Added more polyfills to aid in development, like wrapping console.log in a closure to bypass the console interface error. The timeout accuracy and code clarity has been improved. Server is now upgraded to use gun@0.3, and the level options have been better tailored to the application.
61 lines
1023 B
JavaScript
61 lines
1023 B
JavaScript
/*globals Gun, console, patch, finisher, stats */
|
|
function test(opt) {
|
|
'use strict';
|
|
|
|
opt = patch(opt);
|
|
|
|
var gun, resetDoneTimer, db, confirmed = {};
|
|
resetDoneTimer = finisher();
|
|
gun = new Gun(opt.peers);
|
|
db = gun.get(opt.key);
|
|
|
|
function ack(num) {
|
|
return function (err, ok) {
|
|
if (confirmed[num] && !err) {
|
|
return;
|
|
}
|
|
var request = opt.requests[num - 1];
|
|
request.end = Gun.time.is();
|
|
if (err) {
|
|
request.errors.push(err);
|
|
}
|
|
confirmed[num] = true;
|
|
opt.progress(opt, num);
|
|
resetDoneTimer(db, stats(opt));
|
|
};
|
|
}
|
|
|
|
function run(num) {
|
|
var cb, packet = opt.packet();
|
|
cb = ack(num);
|
|
opt.requests[num - 1] = {
|
|
start: packet.time,
|
|
errors: []
|
|
};
|
|
|
|
db.path(opt.path).path(Gun.text.random()).put(packet, cb);
|
|
|
|
if (num === opt.packets) {
|
|
return;
|
|
}
|
|
|
|
setTimeout(function () {
|
|
run(num + 1);
|
|
}, opt.interval);
|
|
|
|
return opt;
|
|
}
|
|
resetDoneTimer(db, opt);
|
|
|
|
return run(1);
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof window !== 'undefined') {
|
|
if (window.options) {
|
|
test(window.options);
|
|
}
|
|
}
|