Commit 526c3b3694629092893d9152b42e5c2ff86e2814
a few extra checks in test/random.js
Dominic Tarr committed on 5/25/2017, 12:32:33 AMParent: a1931ea47570e58ffa3b8b2ba6d303f69c941994
Files changed
test/random.js | changed |
test/random.js | ||
---|---|---|
@@ -1,4 +1,5 @@ | ||
1 | + | |
1 | 2 | var pull = require('pull-stream') |
2 | 3 | var paramap = require('pull-paramap') |
3 | 4 | var ssbKeys = require('ssb-keys') |
4 | 5 | var u = require('./util') |
@@ -10,8 +11,9 @@ | ||
10 | 11 | var dogs = require('dog-names') |
11 | 12 | |
12 | 13 | var generated = {}, F=100,N=10000 |
13 | 14 | |
15 | + | |
14 | 16 | //build a random network, with n members. |
15 | 17 | function bar (prog) { |
16 | 18 | var r = prog.progress/prog.total |
17 | 19 | var s = '\r', M = 50 |
@@ -105,10 +107,18 @@ | ||
105 | 107 | function latest (sbot, cb) { |
106 | 108 | sbot.friends.hops({hops: 3}, once(function (err, keys) { |
107 | 109 | if(err) return cb(err) |
108 | 110 | 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 | + | |
109 | 115 | for(var k in keys) (function (key) { |
110 | 116 | sbot.latestSequence(key, once(function (err, value) { |
117 | + if(err) { | |
118 | + console.log(key, err, value) | |
119 | + throw err | |
120 | + } | |
111 | 121 | map[key] = isNumber(value) ? value : value.sequence |
112 | 122 | if(--n) return |
113 | 123 | cb(null, map) |
114 | 124 | })) |
@@ -118,10 +128,8 @@ | ||
118 | 128 | |
119 | 129 | var alice = ssbKeys.generate() |
120 | 130 | var bob = ssbKeys.generate() |
121 | 131 | |
122 | - | |
123 | - | |
124 | 132 | var animalNetwork = createSbot({ |
125 | 133 | temp: 'test-random-animals', |
126 | 134 | port: 45451, host: 'localhost', timeout: 20001, |
127 | 135 | replication: {hops: 3}, keys: alice |
@@ -134,11 +142,12 @@ | ||
134 | 142 | console.log(prog) |
135 | 143 | }) |
136 | 144 | ) |
137 | 145 | |
146 | + | |
138 | 147 | tape('generate random network', function (t) { |
139 | 148 | 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) { | |
141 | 150 | if(err) throw err |
142 | 151 | console.log('replicate GRAPH') |
143 | 152 | var c = 0 |
144 | 153 | latest(animalNetwork, function (err, _generated) { |
@@ -161,8 +170,9 @@ | ||
161 | 170 | }) |
162 | 171 | }) |
163 | 172 | |
164 | 173 | tape('read all history streams', function (t) { |
174 | + | |
165 | 175 | var opts = { |
166 | 176 | host: 'localhost', port: 45451, |
167 | 177 | key: alice.id, |
168 | 178 | manifest: animalNetwork.manifest() |
@@ -201,9 +211,9 @@ | ||
201 | 211 | console.log('all histories dumped', c, 'messages in', time, 'at rate', c/time) |
202 | 212 | console.log('read back live:', live, 'over', h, 'histories', listeners, 'listeners') |
203 | 213 | pull( |
204 | 214 | dump.createLogStream(), |
205 | - pull.collect(function (err, ary) { | |
215 | + pull.collect(function (err, ary) { | |
206 | 216 | if(err) throw err |
207 | 217 | console.log(c) |
208 | 218 | t.equal(ary.length, F+N+2) |
209 | 219 | dump.close() |
@@ -234,11 +244,12 @@ | ||
234 | 244 | var connections = 0 |
235 | 245 | |
236 | 246 | animalFriends.on('rpc:connect', function (rpc) { |
237 | 247 | connections++ |
238 | - console.log("CONNECT", c) | |
248 | + c++ | |
249 | + console.log("CONNECT", connections) | |
239 | 250 | rpc.on('closed', function () { |
240 | - console.log("DISCONNECT", -c) | |
251 | + console.log("DISCONNECT", --connections) | |
241 | 252 | }) |
242 | 253 | }) |
243 | 254 | |
244 | 255 | var drain |
@@ -247,15 +258,14 @@ | ||
247 | 258 | animalFriends.replicate.changes(), |
248 | 259 | drain = pull.drain(function (prog) { |
249 | 260 | prog.id = 'animal friends' |
250 | 261 | 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)) | |
254 | 263 | if(prog.progress === target) { |
255 | 264 | console.log("DONE!!!!") |
256 | 265 | var time = (Date.now() - start) / 1000 |
257 | 266 | console.log('replicated', target, 'messages in', time, 'at rate',target/time) |
267 | + t.equal(c, 1, 'everything replicated within a single connection') | |
258 | 268 | animalFriends.close(true) |
259 | 269 | drain.abort() |
260 | 270 | t.end() |
261 | 271 | } |
Built with git-ssb-web