git ssb

6+

Dominic / epidemic-broadcast-trees



Commit 61537ea49c1a1f22f2d8f0ef263fdbef5f2d5e7d

test cancellation on streams

Dominic Tarr committed on 6/5/2017, 8:38:54 AM
Parent: 2744ecd62eb4f3f3bc415d40a981b0a6afc9507e

Files changed

test/stream.jschanged
test/stream.jsView
@@ -4,9 +4,9 @@
44 var pull = require('pull-stream')
55
66
77
8-function Peer (logs) {
8 +function Peer (logs, onRequest) {
99 logs._append = logs._append || []
1010
1111 function onAppend (msg) {
1212 for(var i = 0; i < logs._append.length; i++)
@@ -33,8 +33,9 @@
3333 }
3434 ) ({
3535 seqs: states,
3636 onChange: console.log,
37 + onRequest: onRequest
3738 },
3839 cb)
3940
4041 logs._append.push(stream.onAppend)
@@ -217,7 +218,105 @@
217218 })
218219
219220 })
220221
222 +tape('stream when one peer does not follow', function (t) {
223 + var alice_db = {alice: alice}
224 + var bob_db = {alice: [], bob: bob}
221225
226 + var alice_stream = Peer(alice_db, function (bob_id, seq) {
227 + t.equal(bob_id, 'bob')
228 + t.equal(seq, 3)
229 + bob_requested = true
230 + }) ()
231 + var bob_stream = Peer(bob_db, function () {}) ()
222232
233 + pull(
234 + alice_stream,
235 + bob_stream,
236 + alice_stream
237 + )
223238
239 + t.deepEqual(alice_db.alice, bob_db.alice, 'bob has replicated alice')
240 + t.notDeepEqual(alice_db.bob, bob_db.bob, 'alice has not replicated bob')
241 + t.ok(bob_requested)
242 + console.log(alice_stream.progress())
243 + alice_db.bob = []
244 + alice_stream.request('bob', 0)
245 + t.deepEqual(alice_db.bob, bob_db.bob)
246 + console.log(alice_stream.progress())
247 + console.log(alice_db)
248 + t.end()
249 +})
250 +
251 +
252 +tape('stream when one peer does not follow', function (t) {
253 + var alice_db = {alice: alice}
254 + var bob_db = {alice: [], bob: bob}
255 +
256 + var alice_stream = Peer(alice_db, function (bob_id, seq) {
257 + t.equal(bob_id, 'bob')
258 + t.equal(seq, 3)
259 + bob_requested = true
260 + }) ()
261 + var bob_stream = Peer(bob_db, function () {}) ()
262 +
263 + pull(
264 + alice_stream,
265 + bob_stream,
266 + alice_stream
267 + )
268 +
269 + t.ok(bob_requested)
270 + t.deepEqual(alice_db.alice, bob_db.alice, 'bob has replicated alice')
271 + t.notDeepEqual(alice_db.bob, bob_db.bob, 'alice has not replicated bob')
272 +
273 + console.log(alice_stream.progress())
274 + alice_db.bob = []
275 + alice_stream.request('bob', -1)
276 + t.notDeepEqual(alice_db.bob, bob_db.bob, 'alice has not replicated bob')
277 +
278 + console.log(alice_stream.progress())
279 + console.log(alice_db)
280 + t.end()
281 +})
282 +
283 +tape('alice blocks bob', function (t) {
284 + var alice_db = {alice: alice, bob: []}
285 + var bob_db = {alice: [], bob: bob}
286 +
287 + var alice_stream = Peer(alice_db) ()
288 + var bob_stream = Peer(bob_db) ()
289 +
290 + pull(
291 + alice_stream,
292 + pull.through(function (data) { console.log('alice>>', data) }),
293 + bob_stream,
294 + pull.through(function (data) { console.log('bob>>', data) }),
295 + alice_stream
296 + )
297 + console.log('REPLICATED', alice_stream.progress())
298 +
299 +// t.ok(bob_requested)
300 +// t.deepEqual(alice_db.alice, bob_db.alice, 'bob has replicated alice')
301 +// t.deepEqual(alice_db.bob, bob_db.bob, 'alice has replicated bob')
302 +//
303 +// console.log(alice_stream.progress())
304 +
305 + t.deepEqual(
306 + alice_stream.progress(),
307 + { sync: 2, feeds: 2, recv: 0, send: 0, total: 3, unknown: 0 }
308 + )
309 +
310 + alice_stream.request('bob', -1)
311 + var msg = {author: 'bob', sequence: 4, content: 'BLOCKED'}
312 + bob_db.bob.push(msg)
313 + bob_stream.onAppend(msg)
314 +
315 + t.deepEqual(
316 + alice_stream.progress(),
317 + { sync: 1, feeds: 1, recv: 0, send: 0, total: 3, unknown: 0 }
318 + )
319 +
320 + t.end()
321 +})
322 +

Built with git-ssb-web