git ssb

2+

ev / minsbot



Tree: f1a984b03058530d675879e478d5f867b012af1a

Files: f1a984b03058530d675879e478d5f867b012af1a / test / server.js

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

Built with git-ssb-web