Files: a5863ed6af73f89e56c11e0019e14538eb5c7cae / test / realtime.js
1750 bytesRaw
1 | var cont = require('cont') |
2 | var deepEqual = require('deep-equal') |
3 | var tape = require('tape') |
4 | var pull = require('pull-stream') |
5 | var u = require('./util') |
6 | |
7 | var ssbKeys = require('ssb-keys') |
8 | |
9 | var createSbot = require('../') |
10 | .use(require('../plugins/replicate')) |
11 | .use(require('ssb-friends')) |
12 | |
13 | tape('replicate between 3 peers', function (t) { |
14 | |
15 | var bob = createSbot({ |
16 | temp: 'test-bob', |
17 | // port: 45452, host: 'localhost', |
18 | keys: ssbKeys.generate() |
19 | }) |
20 | |
21 | var alice = createSbot({ |
22 | temp: 'test-alice', |
23 | // port: 45453, host: 'localhost', |
24 | seeds: [bob.getAddress()], |
25 | keys: ssbKeys.generate() |
26 | }) |
27 | |
28 | cont.para([ |
29 | alice.publish(u.follow(bob.id)), |
30 | bob.publish(u.follow(alice.id)) |
31 | ])(function (err) { |
32 | if(err) throw err |
33 | |
34 | var rpc |
35 | alice.connect(bob.getAddress(), function (_, _rpc) { |
36 | rpc = _rpc |
37 | }) |
38 | |
39 | var ary = [] |
40 | pull( |
41 | bob.createHistoryStream({id: alice.id, seq: 0, keys: false, live: true}), |
42 | pull.drain(function (data) { |
43 | console.log(data) |
44 | ary.push(data); |
45 | }) |
46 | ) |
47 | var l = 12 |
48 | var int = setInterval(function () { |
49 | if(!--l) { |
50 | clearInterval(int) |
51 | var _ary = [] |
52 | pull( |
53 | bob.createHistoryStream({id: alice.id, sequence: 0, keys: false}), |
54 | pull.collect(function (err, _ary) { |
55 | t.equal(_ary.length, 12) |
56 | t.deepEqual(ary,_ary) |
57 | bob.close(true); alice.close(true); t.end() |
58 | }) |
59 | ) |
60 | } |
61 | else |
62 | alice.publish({type: 'test', value: new Date()}, |
63 | function (err, msg){ |
64 | if(err) throw err |
65 | console.log('added', msg.key, msg.value.sequence) |
66 | }) |
67 | }, 200) |
68 | |
69 | }) |
70 | }) |
71 | |
72 | |
73 |
Built with git-ssb-web