git ssb

4+

Dominic / scuttlebot



Tree: a5863ed6af73f89e56c11e0019e14538eb5c7cae

Files: a5863ed6af73f89e56c11e0019e14538eb5c7cae / test / server.js

2136 bytesRaw
1
2var cont = require('cont')
3var deepEqual = require('deep-equal')
4var tape = require('tape')
5var pull = require('pull-stream')
6var ssbKeys = require('ssb-keys')
7
8var u = require('./util')
9
10// create 3 servers
11// give them all pub servers (on localhost)
12// and get them to follow each other...
13
14var createSbot = require('../')
15 .use(require('../plugins/replicate'))
16 .use(require('ssb-friends'))
17 .use(require('../plugins/gossip'))
18 .use(require('../plugins/logging'))
19
20tape('replicate between 3 peers', function (t) {
21
22 var alice, bob, carol
23 var dbA = createSbot({
24 temp: 'server-alice',
25 port: 45451, timeout: 1400,
26 keys: alice = ssbKeys.generate(),
27 level: 'info'
28 })
29 var dbB = createSbot({
30 temp: 'server-bob',
31 port: 45452, timeout: 1400,
32 keys: bob = ssbKeys.generate(),
33 seeds: [dbA.getAddress()],
34 level: 'info'
35 })
36 var dbC = createSbot({
37 temp: 'server-carol',
38 port: 45453, timeout: 1400,
39 keys: carol = ssbKeys.generate(),
40 seeds: [dbA.getAddress()],
41 level: 'info'
42 })
43
44 var apub = cont(dbA.publish)
45 var bpub = cont(dbB.publish)
46 var cpub = cont(dbC.publish)
47
48 cont.para([
49 apub(u.pub(dbA.getAddress())),
50 bpub(u.pub(dbB.getAddress())),
51 cpub(u.pub(dbC.getAddress())),
52
53 apub(u.follow(bob.id)),
54 apub(u.follow(carol.id)),
55
56 bpub(u.follow(alice.id)),
57 bpub(u.follow(carol.id)),
58
59 cpub(u.follow(alice.id)),
60 cpub(u.follow(bob.id))
61 ]) (function (err, ary) {
62 if(err) throw err
63
64 var expected = {}
65 expected[alice.id] = expected[bob.id] = expected[carol.id] = 3
66
67 function check(server, name) {
68 var closed = false
69 return server.on('replicate:finish', function (actual) {
70 console.log(actual)
71 if(deepEqual(expected, actual) && !closed) {
72 closed = true
73 done()
74 }
75 })
76 }
77
78 var serverA = check(dbA, 'ALICE')
79 var serverB = check(dbB, 'BOB')
80 var serverC = check(dbC, 'CAROL')
81
82 var n = 2
83
84 function done () {
85 if(--n) return
86 dbA.close(true); dbB.close(true); dbC.close(true)
87 t.ok(true)
88 t.end()
89 }
90 })
91})
92
93
94
95
96
97

Built with git-ssb-web