git ssb

4+

Dominic / scuttlebot



Commit 526c3b3694629092893d9152b42e5c2ff86e2814

a few extra checks in test/random.js

Dominic Tarr committed on 5/25/2017, 12:32:33 AM
Parent: a1931ea47570e58ffa3b8b2ba6d303f69c941994

Files changed

test/random.jschanged
test/random.jsView
@@ -1,4 +1,5 @@
1+
12 var pull = require('pull-stream')
23 var paramap = require('pull-paramap')
34 var ssbKeys = require('ssb-keys')
45 var u = require('./util')
@@ -10,8 +11,9 @@
1011 var dogs = require('dog-names')
1112
1213 var generated = {}, F=100,N=10000
1314
15+
1416 //build a random network, with n members.
1517 function bar (prog) {
1618 var r = prog.progress/prog.total
1719 var s = '\r', M = 50
@@ -105,10 +107,18 @@
105107 function latest (sbot, cb) {
106108 sbot.friends.hops({hops: 3}, once(function (err, keys) {
107109 if(err) return cb(err)
108110 var n = Object.keys(keys).length, map = {}
111+ console.log('Generated network:')
112+ console.log(keys)
113+ if(n !== F+1) throw new Error('not enough feeds:'+n+', expected:'+(F+1))
114+
109115 for(var k in keys) (function (key) {
110116 sbot.latestSequence(key, once(function (err, value) {
117+ if(err) {
118+ console.log(key, err, value)
119+ throw err
120+ }
111121 map[key] = isNumber(value) ? value : value.sequence
112122 if(--n) return
113123 cb(null, map)
114124 }))
@@ -118,10 +128,8 @@
118128
119129 var alice = ssbKeys.generate()
120130 var bob = ssbKeys.generate()
121131
122-
123-
124132 var animalNetwork = createSbot({
125133 temp: 'test-random-animals',
126134 port: 45451, host: 'localhost', timeout: 20001,
127135 replication: {hops: 3}, keys: alice
@@ -134,11 +142,12 @@
134142 console.log(prog)
135143 })
136144 )
137145
146+
138147 tape('generate random network', function (t) {
139148 var start = Date.now()
140- generateAnimals(animalNetwork, {add: animalNetwork.publish}, F, N, function (err) {
149+ generateAnimals(animalNetwork, {add: animalNetwork.publish, id: animalNetwork.id}, F, N, function (err) {
141150 if(err) throw err
142151 console.log('replicate GRAPH')
143152 var c = 0
144153 latest(animalNetwork, function (err, _generated) {
@@ -161,8 +170,9 @@
161170 })
162171 })
163172
164173 tape('read all history streams', function (t) {
174+
165175 var opts = {
166176 host: 'localhost', port: 45451,
167177 key: alice.id,
168178 manifest: animalNetwork.manifest()
@@ -201,9 +211,9 @@
201211 console.log('all histories dumped', c, 'messages in', time, 'at rate', c/time)
202212 console.log('read back live:', live, 'over', h, 'histories', listeners, 'listeners')
203213 pull(
204214 dump.createLogStream(),
205- pull.collect(function (err, ary) {
215+ pull.collect(function (err, ary) {
206216 if(err) throw err
207217 console.log(c)
208218 t.equal(ary.length, F+N+2)
209219 dump.close()
@@ -234,11 +244,12 @@
234244 var connections = 0
235245
236246 animalFriends.on('rpc:connect', function (rpc) {
237247 connections++
238- console.log("CONNECT", c)
248+ c++
249+ console.log("CONNECT", connections)
239250 rpc.on('closed', function () {
240- console.log("DISCONNECT", -c)
251+ console.log("DISCONNECT", --connections)
241252 })
242253 })
243254
244255 var drain
@@ -247,15 +258,14 @@
247258 animalFriends.replicate.changes(),
248259 drain = pull.drain(function (prog) {
249260 prog.id = 'animal friends'
250261 var target = F+N+3
251- console.log(prog, target)
252-// progress.push(prog)
253-// process.stdout.write(bar(prog))
262+ process.stdout.write(bar(prog))
254263 if(prog.progress === target) {
255264 console.log("DONE!!!!")
256265 var time = (Date.now() - start) / 1000
257266 console.log('replicated', target, 'messages in', time, 'at rate',target/time)
267+ t.equal(c, 1, 'everything replicated within a single connection')
258268 animalFriends.close(true)
259269 drain.abort()
260270 t.end()
261271 }

Built with git-ssb-web