From 11c36fc604fa26ea8fd7f1ea0b7de2363203e7c8 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 13 Aug 2021 04:37:31 -0700 Subject: [PATCH] change stun system --- examples/basic/paste.html | 2 +- gun.js | 49 ++++++---- lib/rindexed.js | 21 ++--- test/common.js | 183 +++++++++++++++++++++----------------- test/rad/rad.js | 2 +- 5 files changed, 143 insertions(+), 114 deletions(-) diff --git a/examples/basic/paste.html b/examples/basic/paste.html index 0932e7f6..b4da665b 100644 --- a/examples/basic/paste.html +++ b/examples/basic/paste.html @@ -5,5 +5,5 @@ \ No newline at end of file diff --git a/gun.js b/gun.js index d84bc7e0..045b20e3 100644 --- a/gun.js +++ b/gun.js @@ -363,7 +363,7 @@ if(state === was && (val === known || L(val) <= L(known))){ /*console.log("same");*/ /*same;*/ if(!ctx.miss){ return } } // same } ctx.stun++; // TODO: 'forget' feature in SEA tied to this, bad approach, but hacked in for now. Any changes here must update there. - var aid = msg['#']+ctx.all++, id = {toString: function(){ return aid }, _: ctx}; // this *trick* makes it compatible between old & new versions. + var aid = msg['#']+ctx.all++, id = {toString: function(){ return aid }, _: ctx}; id.toJSON = id.toString; // this *trick* makes it compatible between old & new versions. DBG && (DBG.ph = DBG.ph || +new Date); root.on('put', {'#': id, '@': msg['@'], put: {'#': soul, '.': key, ':': val, '>': state}, _: ctx}); } @@ -825,37 +825,47 @@ var wait = {}; // can we assign this to the at instead, like in once? function any(msg, eve, f){ if(any.stun){ return } - var at = msg.$._, data = at.put, aid, test, tmp; if((tmp = root.pass) && !tmp[id]){ return } - if(!at.has && !at.soul){ data = (u !== (msg.put||'')['='])? msg.put['='] : msg.put } // handles non-core messages. - if('string' == typeof (tmp = Gun.valid(data))){ data = root.$.get(tmp)._.put } // TODO: Can we delete this line of code, because the line below (which was inspired by @rogowski) handles it anyways? - if(u === data && msg.$$){ data = msg.$$._.put } - if(u !== opt.not && u === data){ return } + var at = msg.$._, sat = (msg.$$||'')._, data = (sat||at).put, odd = (!at.has && !at.soul), test = {}, link, tmp; + if(odd || u === data){ // handles non-core + data = (u === ((tmp = msg.put)||'')['='])? (u === (tmp||'')[':'])? tmp : tmp[':'] : tmp['=']; + } + if(link = ('string' == typeof (tmp = Gun.valid(data)))){ + data = (u === (tmp = root.$.get(tmp)._.put))? opt.not? u : data : tmp; + } + if(opt.not && u === data){ return } if(u === opt.stun){ - //if(tmp = root.stun){ tmp = tmp[at.id] || at.$.back(function(back){ return tmp[back.id] || u }); if(tmp && !tmp.end && any.id > (tmp._||'').id){ // this is more thorough, but below seems to work too? - //if((tmp = root.stun) && (tmp = tmp[at.id] || tmp[at.back.id]) && !tmp.end && any.id > (tmp._||'').id){ // if we are in the middle of a write, don't read until it is done, unless our callback was earlier than the write. if((tmp = root.stun) && tmp.on){ - tmp.on(''+(aid = cat.id), test = {}); - !test.run && tmp.on(''+(aid = at.id), test); - !test.run && msg.$$ && tmp.on(''+(aid = msg.$$._.id), test); - if(test.run && any.id > test.run){ // what if I'm less than the last item but more than an earlier item? Don't I need to check first item but add to last item? + cat.$.back(function(a){ // our chain stunned? + tmp.on(''+a.id, test = {}); + if((test.run || 0) < any.id){ return test } // if there is an earlier stun on gapless parents/self. + }); + !test.run && tmp.on(''+at.id, test = {}); // this node stunned? + !test.run && sat && tmp.on(''+sat.id, test = {}); // linked node stunned? + if(any.id > test.run){ if(!test.stun || test.stun.end){ test.stun = tmp.on('stun'); test.stun = test.stun && test.stun.last; } if(test.stun && !test.stun.end){ - (test.stun.add || (test.stun.add = {}))[id] = function(){any(msg,eve,1)} // add ourself to the stun callback list that is called at end of the write. + //if(odd && u === data){ return } + //if(u === msg.put){ return } // "not found" acks will be found if there is stun, so ignore these. + (test.stun.add || (test.stun.add = {}))[id] = function(){ any(msg,eve,1) } // add ourself to the stun callback list that is called at end of the write. return; } } } + if(/*odd &&*/ u === data){ f = 0 } // if data not found, keep waiting/trying. + /*if(f && u === data){ + cat.on('out', opt.out); + return; + }*/ if((tmp = root.hatch) && !tmp.end && u === opt.hatch && !f){ // quick hack! // What's going on here? Because data is streamed, we get things one by one, but a lot of developers would rather get a callback after each batch instead, so this does that by creating a wait list per chain id that is then called at the end of the batch by the hatch code in the root put listener. if(wait[at.$._.id]){ return } wait[at.$._.id] = 1; tmp.push(function(){any(msg,eve,1)}); return; }; wait = {}; // end quick hack. } - //tmp = any.wait || (any.wait = {}); console.log(tmp[at.id] === ''); if(tmp[at.id] !== ''){ tmp[at.id] = tmp[at.id] || setTimeout(function(){tmp[at.id]='';any(msg,eve)},1); return } delete tmp[at.id]; // call: if(opt.on){ opt.ok.call(at.$, data, at.get, msg, eve || any); return } // TODO: Also consider breaking `this` since a lot of people do `=>` these days and `.call(` has slower performance. if(opt.v2020){ opt.ok(msg, eve || any); return } @@ -869,7 +879,8 @@ any.rid = rid; // logic from old version, can we clean it up now? any.id = opt.run || ++root.once; // used in callback to check if we are earlier than a write. // will this ever cause an integer overflow? tmp = root.pass; (root.pass = {})[id] = 1; // Explanation: test trade-offs want to prevent recursion so we add/remove pass flag as it gets fulfilled to not repeat, however map map needs many pass flags - how do we reconcile? - cat.on('out', {get: {}}); + opt.out = opt.out || {get: {}}; + cat.on('out', opt.out); root.pass = tmp; return gun; } else @@ -984,7 +995,7 @@ var id = as.seen.length; (as.wait || (as.wait = {}))[id] = ''; tmp = (cat.ref = (g? d : k? at.ref.get(k) : at.ref))._; - (tmp = (d && (d._||'')['#']) || tmp.soul || tmp.link)? resolve({soul: tmp}) : cat.ref.get(resolve, {run: as.run, /*hatch: 0,*/ v2020:1}); // TODO: BUG! This should be resolve ONLY soul to prevent full data from being loaded. + (tmp = (d && (d._||'')['#']) || tmp.soul || tmp.link)? resolve({soul: tmp}) : cat.ref.get(resolve, {run: as.run, /*hatch: 0,*/ v2020:1, out:{get:{'.':' '}}}); // TODO: BUG! This should be resolve ONLY soul to prevent full data from being loaded. // Fixed now? function resolve(msg, eve){ if(eve){ eve.off(); eve.rid(msg) } // TODO: Too early! Check all peers ack not found. // TODO: BUG maybe? Make sure this does not pick up a link change wipe, that it uses the changign link instead. @@ -992,7 +1003,7 @@ stun(as, msg.$); if(!soul){ soul = []; - msg.$.back(function(at){ + (msg.$$||msg.$).back(function(at){ if(tmp = at.soul || at.link){ return soul.push(tmp) } soul.push(at.get); }); @@ -1024,6 +1035,7 @@ return; } test.run = test.run || as.run; + test.stun = test.stun || as.stun; return; if(this.to.to){ this.the.last.next(test); return; @@ -1046,9 +1058,10 @@ if(!stun){ return } stun.end = noop; // like with the earlier id, cheaper to make this flag a function so below callbacks do not have to do an extra type check. if(stun.the.to === stun && stun === stun.the.last){ delete root.stun } stun.off(); + //console.log("PUT HATCH END", as.run, Object.keys(stun.add||'')); setTimeout.each(Object.keys(stun = stun.add||''), function(cb){ if(cb = stun[cb]){cb()} }); // resume the stunned reads // Any perf reasons to CPU schedule this .keys( ? }).hatch = tmp; // this is not official yet ^ - //console.log(1, "PUT", as.run, as.graph); + //console.only(1, "PUT", as.run, as.graph); (as.via._).on('out', {put: as.out = as.graph, opt: as.opt, '#': ask, _: tmp}); } diff --git a/lib/rindexed.js b/lib/rindexed.js index d3f3af7d..b49673c4 100644 --- a/lib/rindexed.js +++ b/lib/rindexed.js @@ -13,22 +13,23 @@ if (navigator.storage && navigator.storage.estimate) { function Store(opt){ opt = opt || {}; opt.file = String(opt.file || 'radata'); - var db = null, u; + var store = Store[opt.file], db = null, u; + + if(store){ + console.log("Warning: reusing same IndexedDB store and options as 1st."); + return Store[opt.file]; + } + store = Store[opt.file] = function(){}; + try{opt.indexedDB = opt.indexedDB || Store.indexedDB || indexedDB}catch(e){} try{if(!opt.indexedDB || 'file:' == location.protocol){ - var store = {}, s = {}; - store.put = function(f, d, cb){ s[f] = d; cb(null, 1) }; - store.get = function(f, cb){ cb(null, s[f] || u) }; + var s = store.d || (store.d = {}); + store.put = function(f, d, cb){ s[f] = d; setTimeout(function(){ cb(null, 1) },250) }; + store.get = function(f, cb){ setTimeout(function(){ cb(null, s[f] || u) },5) }; console.log('Warning: No indexedDB exists to persist data to!'); return store; }}catch(e){} - var store = function Store(){}; - if(Store[opt.file]){ - console.log("Warning: reusing same IndexedDB store and options as 1st."); - return Store[opt.file]; - } - Store[opt.file] = store; store.start = function(){ var o = indexedDB.open(opt.file, 1); diff --git a/test/common.js b/test/common.js index 3ccc7843..4e0b2eb8 100644 --- a/test/common.js +++ b/test/common.js @@ -19,9 +19,9 @@ describe('Gun', function(){ root.Gun.TESTING = true; require('../lib/store'); require('../lib/rfs'); - console.log("UNDO THIS SO RAD & SEA RUN!"); - //require('./rad/rad.js'); - //require('./sea/sea.js'); + //console.log("UNDO THIS SO RAD & SEA RUN!"); + require('./rad/rad.js'); + require('./sea/sea.js'); } }(this)); //Gun.log.squelch = true; @@ -1059,6 +1059,15 @@ describe('Gun', function(){ }; var gun = Gun(); + var nopasstun = function(done, g){ + g = (g || gun)._.root; + setTimeout(function(){ + expect(g.pass).to.not.be.ok(); + expect(g.stun).to.not.be.ok(); + done && done(); + },9); + } + it.skip('gun chain separation', function(done){ // TODO: UNDO! var gun = Gun(); @@ -1174,13 +1183,13 @@ describe('Gun', function(){ expect(g['z/y/x']).to.be.ok(); expect(g['z/y/x/c']).to.be.ok(); expect(g['z/y/x/c/b']).to.be.ok(); - done(); + nopasstun(done, gun); }); }); it('no not found on incremental write', function(done){ gun.get('nnfoiw').get('y').put({a:1}, function(ack){ if(ack.err){ return } - done(); + nopasstun(done, gun); }) }); it('public mix', function(done){ @@ -1194,8 +1203,9 @@ describe('Gun', function(){ var g = gun._.graph; expect(Object.keys(g['zasdf']||'').sort()).to.be.eql(['_', 'a', 'foo'].sort()); expect(Object.keys(g['zasdf/foo']||'').sort()).to.be.eql(['_', 'bar', 'ah'].sort()); - done(); + nopasstun(done, gun); }; + //setTimeout(function(){ console.log('???', gun._.stun); }, 1700); }); }); @@ -1227,7 +1237,7 @@ describe('Gun', function(){ expect(check.bob.name).to.be('Bob!'); expect('string' == typeof Gun.valid(check.bob.pet)).to.be.ok(); //expect(count.bob).to.be(1); - done(); + nopasstun(done, gun); },10); } }); @@ -1259,7 +1269,7 @@ describe('Gun', function(){ expect(check.bob).to.be('name'); //expect(count.alice).to.be(1); //expect(count.bob).to.be(1); - done(); + nopasstun(done, gun); },10); } }); @@ -1293,7 +1303,7 @@ describe('Gun', function(){ //expect(count.Frisky).to.be(1); //expect(count['undefined']).to.not.be.ok(); if(done.c){return}done.c=1; - done(); + nopasstun(done, gun); },10); } }); @@ -1334,7 +1344,7 @@ describe('Gun', function(){ }); //expect(count.Fluffy).to.be(1); //expect(count.Frisky).to.be(1); - done(); + nopasstun(done, gun); },10); } }); @@ -1367,7 +1377,7 @@ describe('Gun', function(){ //expect(count.Bob).to.be(1); //expect(count['undefined']).to.be(1); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); },10); } }); @@ -1405,7 +1415,7 @@ describe('Gun', function(){ expect(count.Bob).to.be(1); expect(count['undefined']).to.be(1); expect(count['Alice Zzxyz']).to.be(1); - done(); + nopasstun(done, gun); },200); } }); @@ -1451,7 +1461,7 @@ describe('Gun', function(){ //expect(count['Bob']).to.be(1); //expect(count['Alice Zzxyz']).to.be(1); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); },200); } }); @@ -1507,7 +1517,7 @@ describe('Gun', function(){ //expect(count.Alice).to.be(1); //expect(count.Bob).to.be(1); //expect(count['Alice Zzxyz']).to.be(1); - done(); + nopasstun(done, gun); },200); } }); @@ -1553,7 +1563,7 @@ describe('Gun', function(){ expect(count.Fluffy).to.be(1); expect(count.Frisky).to.be(1); expect(count.Fuzzball).to.be(1); - done(); + nopasstun(done, gun); },200); } }); @@ -1598,7 +1608,7 @@ describe('Gun', function(){ expect(check.firsta).to.not.be.ok(); expect(count.first).to.be(1); expect(count.other).to.be(1); - done(); + nopasstun(done, gun); },200); } }); @@ -1637,8 +1647,8 @@ describe('Gun', function(){ expect(check.alice.PhD).to.be(true); //expect(count.alice).to.be(2); //expect(count.bob).to.be(1); - if(done.c){return} - done();done.c=1; + if(done.c){return} done.c=1; + nopasstun(done, gun); },50); } }); @@ -1710,7 +1720,7 @@ describe('Gun', function(){ expect(check.alice.age).to.be(24); expect(check.bob.age).to.be(26); expect(check.alice.PhD).to.be(true); - done(); + nopasstun(done, gun); },10); } }); @@ -1732,7 +1742,7 @@ describe('Gun', function(){ expect(check.bob).to.be('name'); expect(check.Alice).to.be('name'); if(done.c){return}done.c=1; - done(); + nopasstun(done, gun); },10); } }); @@ -1804,7 +1814,7 @@ describe('Gun', function(){ expect(check.alice).to.be('name'); expect(check.bob).to.be('name'); expect(check.Alice).to.be('name'); - done(); + nopasstun(done, gun); },10); } }); @@ -1826,7 +1836,7 @@ describe('Gun', function(){ expect(check['ACME INC']).to.be('work'); expect(check['ACME INC.']).to.be('work'); if(done.c){return}done.c=1; - done(); + nopasstun(done, gun); },10); } }); @@ -1897,7 +1907,7 @@ describe('Gun', function(){ expect(check['GUN INC']).to.be('work'); expect(check['ACME INC']).to.be('work'); expect(check['ACME INC.']).to.be('work'); - done(); + nopasstun(done, gun); },10); } }); @@ -1925,7 +1935,7 @@ describe('Gun', function(){ expect(check.ACME.name).to.be('ACME'); expect(check.ACME.corp).to.be('C'); if(done.c){return}done.c=1; - done(); + nopasstun(done, gun); },10); } }); @@ -2012,7 +2022,7 @@ describe('Gun', function(){ expect(check.GUN.name).to.be('GUN'); expect(check.ACME.name).to.be('ACME'); expect(check.ACME.corp).to.be('C'); - done(); + nopasstun(done, gun); },10); } }); @@ -2036,7 +2046,7 @@ describe('Gun', function(){ expect(check.ACME).to.be('name'); expect(check.ACMEINC).to.be('name'); if(done.c){return}done.c=1; - done(); + nopasstun(done, gun); },10); } }); @@ -2117,7 +2127,7 @@ describe('Gun', function(){ expect(check.GUN).to.be('name'); expect(check.ACME).to.be('name'); expect(check.ACMEINC).to.be('name'); - done(); + nopasstun(done, gun); },10); } }); @@ -2140,7 +2150,7 @@ describe('Gun', function(){ expect(check.TX).to.be('state'); expect(check.MA).to.be('state'); if(done.c){return}done.c=1; - done(); + nopasstun(done, gun); },10); } }); @@ -2244,7 +2254,7 @@ describe('Gun', function(){ expect(check.CA).to.be('state'); expect(check.TX).to.be('state'); expect(check.MA).to.be('state'); - done(); + nopasstun(done, gun); },10); } }); @@ -2269,7 +2279,7 @@ describe('Gun', function(){ expect(check.TX).to.be('code'); expect(check.MA).to.be('code'); if(done.c){return}done.c=1; - done(); + nopasstun(done, gun); },10); } }); @@ -2416,7 +2426,7 @@ describe('Gun', function(){ expect(check.CA).to.be('code'); expect(check.TX).to.be('code'); expect(check.MA).to.be('code'); - done(); + nopasstun(done, gun); },10); } }); @@ -2440,7 +2450,7 @@ describe('Gun', function(){ expect(check.TX).to.be('state'); expect(check.MA).to.be('state'); if(done.c){return}done.c=1; - done(); + nopasstun(done, gun); },10); } }); @@ -2585,7 +2595,7 @@ describe('Gun', function(){ expect(check.CA).to.be('state'); expect(check.TX).to.be('state'); expect(check.MA).to.be('state'); - done(); + nopasstun(done, gun); },10); } }); @@ -2677,7 +2687,7 @@ describe('Gun', function(){ expect(check.CA2).to.be('Second'); expect(check.NY2).to.be('Second'); expect(check.NY3).to.be('Third'); - done(); + nopasstun(done, gun); },10); } }); @@ -2704,7 +2714,7 @@ describe('Gun', function(){ ref.once(function(data){ //console.log("*+*+*+*+*+**+*+*"); expect(data).to.be('z'); - done(); + nopasstun(done); }); }, 25); }, 25); @@ -2736,7 +2746,7 @@ describe('Gun', function(){ },500);}); });*/ - it.only('get node after recursive field', function(done){ + it('get node after recursive field', function(done){ var bob = {age: 29, name: "Bob!"}; var cat = {name: "Fluffy", species: "kitty"}; var user = {bob: bob}; @@ -2752,7 +2762,7 @@ describe('Gun', function(){ expect(data.age).to.be(29); expect(data.name).to.be("Bob!"); expect('string' == typeof Gun.valid(data.pet)).to.ok(); - done(); + nopasstun(done); },300); }); }); @@ -2783,7 +2793,7 @@ describe('Gun', function(){ done.parent = data; //console.log("*********parent", data); if(done.c){ return } done.c = 1; - done(); // TODO: Add more meaningful checks! + nopasstun(done, gun); // TODO: Add more meaningful checks! }); }); @@ -2795,7 +2805,7 @@ describe('Gun', function(){ }).get(function(at){ //console.log("?????", at); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); }); }); @@ -2815,7 +2825,7 @@ describe('Gun', function(){ expect(check['2-2'].what).to.be('you.'); expect(count['1-1']).to.be(1); expect(count['2-2']).to.be(1); - done(); + nopasstun(done, gun); },50); } }); @@ -2839,7 +2849,7 @@ describe('Gun', function(){ expect(data.group).to.be('awesome'); expect(data.married).to.be(true); expect(data.name).to.be('Alice'); - done(); + nopasstun(done, gun); }); }); @@ -2877,7 +2887,7 @@ describe('Gun', function(){ expect(check.dave.name).to.be('Dave'); expect(check.dave.group).to.be('awesome'); expect(check.dave.married).to.be(true); - done(); + nopasstun(done, gun); },50); } }); @@ -2955,7 +2965,7 @@ describe('Gun', function(){ expect(done.pub).to.be.ok(); expect(done.alias).to.be.ok(); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); },100); }) },100); @@ -2983,7 +2993,7 @@ describe('Gun', function(){ expect(data.zip).to.be('999999'); if(!done.s){ return } if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun2); }); gun2.get('stef').once(function(data){ //Object {_: Object, address: Object} "stef" //console.log("**************", data);return; @@ -2992,7 +3002,7 @@ describe('Gun', function(){ expect(data.address).to.be.ok(); if(!done.a){ return } if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun2); }); },1200); }); @@ -3021,7 +3031,7 @@ describe('Gun', function(){ done.name = true; expect(done.age).to.be.ok(); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); }); }); }); @@ -3049,7 +3059,7 @@ describe('Gun', function(){ done.name = true; expect(done.age).to.be.ok(); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); }); },400); }); @@ -3071,7 +3081,7 @@ describe('Gun', function(){ done.name = true; expect(done.age).to.be.ok(); if(done.c){return}done.c=1; - done(); + nopasstun(done, gun); }); }); @@ -3093,7 +3103,7 @@ describe('Gun', function(){ done.name = true; expect(done.age).to.be.ok(); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); }); },400); }); @@ -3115,7 +3125,7 @@ describe('Gun', function(){ expect(data.hello).to.be('world'); expect(data.goodbye).to.be('mars'); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); }); }); }); @@ -3138,7 +3148,7 @@ describe('Gun', function(){ expect(data.hello).to.be('world'); expect(data.goodbye).to.be('mars'); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); }); },400); }); @@ -3178,7 +3188,7 @@ describe('Gun', function(){ //console.log(check); if(check.on['asdf'] && check.on['fdsa'] && check.once['asdf'] && check.once['fdsa']){ if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); } }) }, 1200); @@ -3210,7 +3220,7 @@ describe('Gun', function(){ expect(check.levelB3.levelB4).to.eql({'#':"level1/levelB2/levelB3/levelB4"}); expect(check.levelB4.levelB5).to.be("world"); - done(); + nopasstun(done, gun); }, 250); }); gun.get('level1').map().map().map().map().on(function(v,k){ log('*',5,k,v); check[k] = v; }); // see test below @@ -3231,7 +3241,7 @@ describe('Gun', function(){ check.to = check.to || setTimeout(function(){ expect(check.levelA5).to.be('hello'); expect(check.levelB5).to.be('world'); - done(); + nopasstun(done, gun); }, 20); }); }, 1000); @@ -3287,9 +3297,9 @@ describe('Gun', function(){ && check.asdf1.pub === 'asdf' && check.asdf1.name === 'timber' && check.C2.pub === 'fdsa' && check.C2.y === 'mark' && check.asdf2.pub === 'asdf' && check.asdf2.name === 'timber'){ - done(); + nopasstun(done, gun2); } - }); + }, 150); }); },70); @@ -3312,7 +3322,7 @@ describe('Gun', function(){ expect(done.one).to.be("ASDF"); expect(done.two).to.be("mark"); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); }; setTimeout(function(){ @@ -3348,7 +3358,7 @@ describe('Gun', function(){ expect(done.alias.alias).to.be("mark"); expect(done.alias.born).to.be(1); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); }); },400); }, 1000); @@ -3367,7 +3377,7 @@ describe('Gun', function(){ if(1 === data.a && 3 === data.c){ if(done.c){ return } done.c = 1; //console.log("-------"); - done(); + nopasstun(done, gun); } }); @@ -3390,7 +3400,7 @@ describe('Gun', function(){ check[data] = true; if(check.alicethezombie && check.bobthezombie){ if(done.c){return}done.c=1; - done(); + setTimeout(function(){ nopasstun(done, gun) },9); } }); //console.debug.i=1;console.log("--------------"); @@ -3418,7 +3428,7 @@ describe('Gun', function(){ check[k] = (check[k] || 0) + 1; if(1 === check.alice && 1 === check.bob && 1 === check.carl){ if(done.c){return}done.c=1; - done(); + setTimeout(function(){ nopasstun(done, gun) },9); } }); @@ -3446,7 +3456,7 @@ describe('Gun', function(){ expect(check.dave.age).to.be(25); expect(check.eve).to.not.be.ok(); if(done.c){return}done.c=1; - done(); + setTimeout(function(){ nopasstun(done, gun) },9); } },600); }); @@ -3468,7 +3478,7 @@ describe('Gun', function(){ } if(done.one && done.two){ if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); } }); list.get('message').put('hello world'); // outputs "message: hello world" @@ -3510,7 +3520,8 @@ describe('Gun', function(){ expect(val).to.be('hello'); if(done.c){ return } done.c = 1; setTimeout(function(){ - done(); + nopasstun(0, b); + nopasstun(done, d); },1700); }); }); @@ -3537,7 +3548,7 @@ describe('Gun', function(){ setTimeout(function(){ if(done.fbb && done.t && done.bzl){ if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); } },100); }); @@ -3555,7 +3566,7 @@ describe('Gun', function(){ gun.get('ds/safe').once(function(data){ expect(gun.back(-1)._.graph['ds/safe'].b).to.not.be.ok(); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); }); }); @@ -3594,8 +3605,8 @@ describe('Gun', function(){ setTimeout(function(){ expect(done.c).to.be(1); - if(done.d){ return } - done(); done.d = 1; + if(done.d){ return } done.d = 1; + nopasstun(done, gun); },50); }, 50); }, 1000); @@ -3615,7 +3626,7 @@ describe('Gun', function(){ if(!done.u){ return } expect(done.u).to.be.ok(); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); });//, {v2020:1}); //console.log("----------"); @@ -3627,7 +3638,7 @@ describe('Gun', function(){ if(!done.a){ return } expect(done.a).to.be.ok(); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); }, {v2020:1}); }, 1000); }); @@ -3644,7 +3655,7 @@ describe('Gun', function(){ a.once(function(data){ expect(data.profile).to.be.eql({'#': 'sabnbprofile'}); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); }) }, 100); }, 100); @@ -3681,7 +3692,7 @@ describe('Gun', function(){ clearTimeout(end); end = setTimeout(function(){ //console.log("?", c, check, Object.keys(check), gun._.graph); if(!Object.empty(check)){ return } //if(Gun.obj.map(check, function(v){ if(v){ return v } })){ return } - done(); + nopasstun(done, gun); },9); }); @@ -3715,7 +3726,7 @@ describe('Gun', function(){ }); it('get map should not slowdown', function(done){ - this.timeout(5000); + this.timeout(9000); var gun = Gun({test_no_peer:true}).get('g/m/no/slow'); //console.log("---------- setup data done -----------"); var prev, diff, max = 90, total = 500, largest = -1, gone = {}, u; @@ -3737,7 +3748,7 @@ describe('Gun', function(){ clearTimeout(many); expect('number' === typeof diff).to.be.ok(); if(done.c){ return } done.c = 1; - done(); + nopasstun(done, gun); return; } prev = +new Date; @@ -3755,7 +3766,7 @@ describe('Gun', function(){ var gun = Gun(); gun.get('c/p/c').get('a').put('lol', function(ack){ - done(); + nopasstun(done, gun); }); }); @@ -3773,7 +3784,7 @@ describe('Gun', function(){ check['b'+data.property] = 1; if(check.avalue && check.bvalue && check.anewValue && check.bnewValue){ if(done.c){ return } done.c = true; - done(); + nopasstun(done, gun); } }); @@ -3793,7 +3804,7 @@ describe('Gun', function(){ gun.get('who').get('all').once(function(data){ expect(data.what).to.be.ok(); expect(data.when).to.be.ok(); - done(); + nopasstun(done, gun); }); }); //}); @@ -3808,7 +3819,7 @@ describe('Gun', function(){ gun.get('s/r/who').get('said').set(ref, function(ack){ /*console.log('###', ack)*/ }); gun.get('s/r/who').get('said').map().once(function(data){ expect(data.what).to.be.ok(); - done(); + nopasstun(done, gun); }) }); @@ -3858,8 +3869,9 @@ describe('Gun', function(){ return; } expect(v.num).to.be(4); - done(); + nopasstun(done, gun); }); + //return; setTimeout(function(){ @@ -3950,7 +3962,9 @@ describe('Gun', function(){ expect(check.A).to.be('message'); expect(check.B).to.be('message'); expect(check.C).to.be('message'); - done(); + nopasstun(0, gunA); + nopasstun(0, gunB); + nopasstun(done, gunC); }, 100); }); @@ -3981,7 +3995,8 @@ describe('Gun', function(){ var err = at.err, data = at.put, field = at.get; //console.log("*****2", data); expect(data).to.be(undefined); - done(); + if(done.c){ return } done.c = 1; + nopasstun(done, gun); }); }); @@ -3996,7 +4011,7 @@ describe('Gun', function(){ var err = at.err, data = at.put, field = at.get; //console.log("*****2", data); expect(data).to.be(undefined); - done(); + nopasstun(done, gun); }); },400); }); @@ -4012,8 +4027,8 @@ describe('Gun', function(){ //console.log("***** 2", data); expect(data.age).to.be(29); expect(data.name).to.be('Bob!'); - if(done.c){ return } - done(); done.c = 1; + if(done.c){ return } done.c = 1; + nopasstun(done, gun); }); }, 1000); });return; diff --git a/test/rad/rad.js b/test/rad/rad.js index c3e8973d..5ed79912 100644 --- a/test/rad/rad.js +++ b/test/rad/rad.js @@ -434,7 +434,7 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam }); }); - it('small range twice', async function(done){ + it('small range twice', function(done){ var check = {}; var gun = Gun(); gun.get('peoplez').get('alice').put({cool: 'beans'});