Files: 12e5d3c2c7b5bcd8cdbf500ac017d10708c07907 / test / index.js
2117 bytesRaw
1 | var tape = require('tape') |
2 | var ssbKeys = require('ssb-keys') |
3 | var path = require('path') |
4 | var rmrf = require('rimraf') |
5 | var createSbot = require('scuttlebot') |
6 | .use(require('../')) // |
7 | |
8 | // .use(require('ssb-friends')) |
9 | // .use(require('../plugins/gossip')) |
10 | // .use(require('../plugins/logging')) |
11 | |
12 | var alice = createSbot({ |
13 | temp: 'ooo_a', |
14 | timeout: 1000, |
15 | port: 34597, |
16 | keys: ssbKeys.generate() |
17 | }) |
18 | var bob = createSbot({ |
19 | temp: 'ooo_b', |
20 | timeout: 1000, |
21 | port: 34598, |
22 | host: 'localhost', timeout: 20001, |
23 | replicate: {hops: 3, legacy: false}, |
24 | keys: ssbKeys.generate() |
25 | }) |
26 | |
27 | var carol_path = path.join('/tmp/test-ssb-ooo_carol/') |
28 | require('rimraf').sync(carol_path) |
29 | |
30 | var carol = createSbot({ |
31 | path: carol_path, |
32 | timeout: 1000, |
33 | port: 34599, |
34 | keys: ssbKeys.generate() |
35 | }) |
36 | |
37 | var m1, m2 |
38 | |
39 | tape('connect', function (t) { |
40 | alice.connect(bob.getAddress(), function (err) { |
41 | if(err) throw err |
42 | }) |
43 | carol.connect(bob.getAddress(), function (err) { |
44 | if(err) throw err |
45 | }) |
46 | var start = Date.now() |
47 | alice.publish({type: 'test', msg: 'hello'}, function (err, data) { |
48 | if(err) throw err |
49 | console.log(data) |
50 | m1 = data |
51 | carol.ooo.get(data.key, function (err, _data) { |
52 | t.deepEqual(_data.value, data.value, 'received the message!') |
53 | console.log('time', Date.now() - start) |
54 | |
55 | alice.publish({type: 'test2', msg: 'hello2'}, function (err, data) { |
56 | m2 = data |
57 | var start = Date.now() |
58 | carol.ooo.get(data.key, function (err, _data) { |
59 | if(err) throw err |
60 | console.log('time2', Date.now() - start) |
61 | t.deepEqual(_data.value, data.value, 'received the 2nd message!') |
62 | alice.close() |
63 | bob.close() |
64 | carol.close(t.end) |
65 | }) |
66 | }) |
67 | }) |
68 | }) |
69 | }) |
70 | |
71 | |
72 | tape('reopen', function (t) { |
73 | var carol = createSbot({ |
74 | path: carol_path, |
75 | timeout: 1000, |
76 | port: 34599, |
77 | keys: ssbKeys.generate() |
78 | }) |
79 | |
80 | carol.ooo.get(m1.key, function (err, data) { |
81 | t.deepEqual(data.value, m1.value) |
82 | carol.ooo.get(m2.key, function (err, data) { |
83 | t.deepEqual(data.value, m2.value) |
84 | t.end() |
85 | carol.close() |
86 | }) |
87 | }) |
88 | }) |
89 | |
90 |
Built with git-ssb-web