mirror of
https://github.com/amark/gun.git
synced 2025-05-11 18:29:59 +00:00
fix axe
This commit is contained in:
parent
0bcd5730cf
commit
e0390ebd36
2
axe.js
2
axe.js
@ -218,7 +218,7 @@
|
||||
var S = (+new Date); // STATS!
|
||||
var routes = axe.routes || (axe.routes = {}); // USE RAD INSTEAD! TMP TESTING!
|
||||
var peers = {};
|
||||
Object.keys(msg.put).forEach(function(soul, node){ node = msg.put[soul];
|
||||
//Object.keys(msg.put).forEach(function(soul, node){ node = msg.put[soul];
|
||||
setTimeout.each(Object.keys(msg.put), function(soul, node){ node = msg.put[soul];
|
||||
var hash = soul; //Gun.obj.hash({'#': soul});
|
||||
var to = routes[hash];
|
||||
|
2
gun.js
2
gun.js
@ -1156,7 +1156,7 @@
|
||||
var stat = console.STAT || {};
|
||||
//console.log('HEAR:', peer.id, (raw||'').slice(0,250), ((raw||'').length / 1024 / 1024).toFixed(4));
|
||||
|
||||
//console.log(setTimeout.turn.s.length, 'stacks', parseFloat((-(LT - (LT = +new Date))/1000).toFixed(3)), 'sec', parseFloat(((LT-ST)/1000 / 60).toFixed(1)), 'up', stat.peers||0, 'peers', stat.has||0, 'has', stat.memhused, stat.memused, stat.memax, 'heap mem max');
|
||||
console.log(setTimeout.turn.s.length, 'stacks', parseFloat((-(LT - (LT = +new Date))/1000).toFixed(3)), 'sec', parseFloat(((LT-ST)/1000 / 60).toFixed(1)), 'up', stat.peers||0, 'peers', stat.has||0, 'has', stat.memhused, stat.memused, stat.memax, 'heap mem max');
|
||||
}catch(e){ console.log('DBG err', e) }}
|
||||
|
||||
hear.d += raw.length||0 ; ++hear.c } // STATS!
|
||||
|
170
test/panic/latency.js
Normal file
170
test/panic/latency.js
Normal file
@ -0,0 +1,170 @@
|
||||
// this has Alice read data, measuring its latency, while other browsers are flooding relay with updates.
|
||||
var config = {
|
||||
IP: require('ip').address(),
|
||||
port: 8765,
|
||||
servers: 1,
|
||||
browsers: 2,
|
||||
each: 10000,
|
||||
burst: 10,
|
||||
wait: 1,
|
||||
route: {
|
||||
'/': __dirname + '/index.html',
|
||||
'/gun.js': __dirname + '/../../gun.js',
|
||||
'/jquery.js': __dirname + '/../../examples/jquery.js',
|
||||
'/sea.js': __dirname + '/../../sea.js',
|
||||
'/yson.js': __dirname + '/../../lib/yson.js'
|
||||
},
|
||||
dir: __dirname
|
||||
}
|
||||
|
||||
var panic = require('panic-server');
|
||||
panic.server().on('request', function(req, res){ // Static server
|
||||
config.route[req.url] && require('fs').createReadStream(config.route[req.url]).pipe(res);
|
||||
}).listen(config.port); // Start panic server.
|
||||
|
||||
// In order to tell the clients what to do,
|
||||
// We need a way to reference all of them.
|
||||
var clients = panic.clients;
|
||||
|
||||
// Some of the clients may be NodeJS servers on different machines.
|
||||
// PANIC manager is a nifty tool that lets us remotely spawn them.
|
||||
var manager = require('panic-manager')();
|
||||
manager.start({
|
||||
clients: Array(config.servers).fill().map(function(u, i){ // Create a bunch of servers.
|
||||
return {
|
||||
type: 'node',
|
||||
port: config.port + (i + 1) // They'll need unique ports to start their servers on, if we run the test on 1 machine.
|
||||
}
|
||||
}),
|
||||
panic: 'http://' + config.IP + ':' + config.port // Auto-connect to our panic server.
|
||||
});
|
||||
|
||||
// Now lets divide our clients into "servers" and "browsers".
|
||||
var servers = clients.filter('Node.js');
|
||||
var browsers = clients.excluding(servers);
|
||||
var alice = browsers.pluck(1);
|
||||
var others = browsers.excluding(alice);
|
||||
|
||||
describe("Test vanishing property "+ config.browsers +" browser(s) across "+ config.servers +" server(s)!", function(){
|
||||
|
||||
// We'll have to manually launch the browsers,
|
||||
// So lets up the timeout so we have time to do that.
|
||||
this.timeout(5 * 60 * 1000);
|
||||
|
||||
it("Servers have joined!", function(){
|
||||
// Alright, lets wait until enough gun server peers are connected.
|
||||
return servers.atLeast(config.servers);
|
||||
});
|
||||
|
||||
it("GUN has spawned!", function(){
|
||||
// Once they are, we need to actually spin up the gun server.
|
||||
var tests = [], i = 0;
|
||||
servers.each(function(client){
|
||||
// for each server peer, tell it to run this code:
|
||||
tests.push(client.run(function(test){
|
||||
// NOTE: Despite the fact this LOOKS like we're in a closure...
|
||||
// it is not! This code is actually getting run
|
||||
// in a DIFFERENT machine or process!
|
||||
var env = test.props;
|
||||
// As a result, we have to manually pass it scope.
|
||||
test.async();
|
||||
// Clean up from previous test.
|
||||
try{ require('fs').unlinkSync(env.i+'data.json') }catch(e){}
|
||||
var server = require('http').createServer(function(req, res){
|
||||
res.end("I am "+ env.i +"!");
|
||||
});
|
||||
// Launch the server and start gun!
|
||||
var Gun = require(env.config.dir+'/../../');
|
||||
// Attach the server to gun.
|
||||
//var gun = Gun({file: env.i+'data', web: server});
|
||||
var gun = Gun({file: env.i+'data', web: server, rad: false, localStorage: false});
|
||||
server.listen(env.config.port + env.i, function(){
|
||||
// This server peer is now done with the test!
|
||||
// It has successfully launched.
|
||||
test.done();
|
||||
});
|
||||
//setInterval(function(){ console.log("CPU turns stacked:", setTimeout.turn.s.length) },1000);
|
||||
}, {i: i += 1, config: config}));
|
||||
});
|
||||
// NOW, this is very important:
|
||||
// Do not proceed to the next test until
|
||||
// every single server (in different machines/processes)
|
||||
// have ALL successfully launched.
|
||||
return Promise.all(tests);
|
||||
});
|
||||
|
||||
it(config.browsers +" browser(s) have joined!", function(){
|
||||
console.log("PLEASE OPEN http://"+ config.IP +":"+ config.port +" IN "+ config.browsers +" BROWSER(S)!");
|
||||
return browsers.atLeast(config.browsers);
|
||||
});
|
||||
|
||||
it("Browsers initialized gun!", function(){
|
||||
var tests = [], i = 0;
|
||||
browsers.each(function(client, id){
|
||||
tests.push(client.run(function(test){
|
||||
try{ localStorage.clear() }catch(e){}
|
||||
try{ indexedDB.deleteDatabase('radata') }catch(e){}
|
||||
var env = test.props;
|
||||
var gun = Gun({retry: 2, peers: 'http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun'});
|
||||
window.gun = gun;
|
||||
}, {i: i += 1, config: config}));
|
||||
});
|
||||
return Promise.all(tests);
|
||||
});
|
||||
|
||||
it("Start flooding", function(){
|
||||
var tests = [], i = 0;
|
||||
others.each(function(client, id){
|
||||
tests.push(client.run(function(test){
|
||||
console.log("I SHALL FLOOD");
|
||||
test.async();
|
||||
var config = test.props.config;
|
||||
|
||||
gun.get('test').get('latency').put("hello world");
|
||||
|
||||
var go = setInterval(function(){
|
||||
var burst = config.burst;
|
||||
while(--burst){
|
||||
console.log(burst);
|
||||
gun.get(String.random(Math.random()*100)).get(String.random(Math.random()*10)).put(String.random(Math.random()*1000))
|
||||
}
|
||||
},config.wait);
|
||||
|
||||
setTimeout(function(){
|
||||
test.done();
|
||||
setTimeout(function(){ clearInterval(go) }, 2000);
|
||||
}, 1000 * 10);
|
||||
}, {i: i += 1, config: config}));
|
||||
});
|
||||
return Promise.all(tests);
|
||||
});
|
||||
|
||||
it("Alice reads during flood", function(){
|
||||
return alice.run(function(test){
|
||||
console.log("I AM ALICE", gun.back('opt.pid'));
|
||||
$('body').css('background', 'red');
|
||||
test.async();
|
||||
var S = +new Date;
|
||||
gun.get('test').get('latency').on(function(data){
|
||||
var latency = +new Date - S;
|
||||
console.log(latency, data);
|
||||
if(!data){ return }
|
||||
//test.done();
|
||||
});
|
||||
}, config);
|
||||
});
|
||||
|
||||
after("Everything shut down.", function(){
|
||||
// which is to shut down all the browsers.
|
||||
browsers.run(function(){
|
||||
setTimeout(function(){
|
||||
return;
|
||||
location.reload();
|
||||
}, 15 * 1000);
|
||||
});
|
||||
// And shut down all the servers.
|
||||
return servers.run(function(){
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
})
|
@ -1,5 +1,4 @@
|
||||
// but maybe you can try to recreate it locally. two peers. pushing a profile image 100k+ and reading each other. then kill 1 peer, and reset the relay data...
|
||||
// {profile: {image: "100kb", name: 'lol"}}
|
||||
// test SEA end to end.
|
||||
var config = {
|
||||
IP: require('ip').address(),
|
||||
port: 8765,
|
||||
|
Loading…
x
Reference in New Issue
Block a user