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