git ssb

4+

Dominic / scuttlebot



Commit a89135a1e760fdee52632c1be4d8c2fd312faee8

update tests to use ssb-ebt instead of legacy replication

Dominic Tarr committed on 3/5/2018, 8:05:07 AM
Parent: 0f633f3396be68d6207ec3d2fd1d1f180f2a4662

Files changed

test/block.jschanged
test/block2.jschanged
test/block3.jschanged
test/random.jschanged
test/realtime.jschanged
test/server.jschanged
test/block.jsView
@@ -6,8 +6,9 @@
66
77 var createSbot = require('../')
88 .use(require('../plugins/replicate'))
99 .use(require('ssb-friends'))
10 + .use(require('ssb-ebt'))
1011
1112 var toAddress = require('../lib/util').toAddress
1213
1314 function once (fn) {
@@ -25,41 +26,39 @@
2526 // 1. when bob tries to connect to alice, she refuses.
2627 // 2. alice never tries to connect to bob. (removed from peers)
2728 // 3. carol will not give bob any, she will not give him any data from alice.
2829
30 +var crypto = require('crypto')
31 +function seed (name) {
32 + return crypto.createHash('sha256').update(name).digest()
33 +}
34 +
2935 var alice = createSbot({
3036 temp:'test-block-alice', timeout: 1400,
31- keys:ssbKeys.generate()
37 + keys:ssbKeys.generate(null, seed('alice')),
38 + replicate: { legacy: false }
3239 })
3340
3441 var bob = createSbot({
3542 temp: 'test-block-bob', timeout: 600,
36- keys:ssbKeys.generate()
43 + keys:ssbKeys.generate(null, seed('bob')),
44 + replicate: { legacy: false }
3745 })
3846
3947 var carol = createSbot({
4048 temp: 'test-block-carol', timeout: 600,
41- keys:ssbKeys.generate()
49 + keys:ssbKeys.generate(null, seed('carol')),
50 + replicate: { legacy: false }
51 +
4252 })
4353
44-//carol.post(function (data) {
45-// console.log('CAROL RECEIVED', names[data.value.author])
46-// console.log(data.value)
47-//})
48-
4954 var names = {}
5055 names[alice.id] = 'alice'
5156 names[bob.id] = 'bob'
5257 names[carol.id] = 'carol'
5358
5459 tape('alice blocks bob, and bob cannot connect to alice', function (t) {
5560
56-// console.log({
57-// alice: alice.id,
58-// bob: bob.id,
59-// carol: carol.id
60-// })
61-
6261 //in the beginning alice and bob follow each other
6362 cont.para([
6463 cont(alice.publish)(u.follow(bob.id)),
6564 cont(bob .publish)(u.follow(alice.id)),
@@ -77,17 +76,15 @@
7776
7877 //get the next messages that are replicated to alice and bob,
7978 //and check that these are the correct follow messages.
8079 var bobCancel = bob.post(once(function (op) {
81- console.log('BOB_POST', op)
8280 //should be the alice's follow(bob) message.
8381 t.equal(op.value.author, alice.id, 'bob expected message from alice')
8482 t.equal(op.value.content.contact, bob.id, 'bob expected message to be about bob')
8583 next()
8684 }), false)
8785
8886 var aliceCancel = alice.post(once(function (op) {
89- console.log('ALICE_POST', op)
9087 //should be the bob's follow(alice) message.
9188 t.equal(op.value.author, bob.id, 'alice expected to receive a message from bob')
9289 t.equal(op.value.content.contact, alice.id, 'alice expected received message to be about alice')
9390 next()
@@ -96,12 +93,8 @@
9693 if(--n) return
9794
9895 rpc.close(true, function () {
9996 aliceCancel(); bobCancel()
100- console.log('ALICE BLOCKS BOB', {
101- source: alice.id, dest: bob.id
102- })
103-
10497 alice.publish(u.block(bob.id))
10598 (function (err) {
10699 if(err) throw err
107100
@@ -129,9 +122,8 @@
129122 t.ok(err, 'bob is blocked, should fail to connect to alice')
130123
131124
132125 var carolCancel = carol.post(function (msg) {
133- console.log('CAROL RECV', msg, alice.id)
134126 if(msg.author === alice.id) {
135127 if(msg.sequence == 2)
136128 t.end()
137129 }
@@ -139,9 +131,8 @@
139131
140132 //but carol, should, because she is not blocked.
141133 carol.connect(alice.getAddress(), function (err, rpc) {
142134 if(err) throw err
143- console.log('CAROL CONNECTED TO ALICE', carol.id, alice.id)
144135 rpc.on('closed', function () {
145136 carolCancel()
146137 pull(
147138 carol.createHistoryStream({id: alice.id, seq: 0, live: false}),
@@ -168,11 +159,9 @@
168159 tape('carol does not let bob replicate with alice', function (t) {
169160 //first, carol should have already replicated with alice.
170161 //emits this event when did not allow bob to get this data.
171162 bob.once('replicate:finish', function (vclock) {
172- console.log('BOB REPLICATED FROM CAROL')
173163 t.equal(vclock[alice.id], 1)
174- console.log('ALICE:', alice.id)
175164 //t.end()
176165 })
177166 bob.connect(carol.getAddress(), function(err, rpc) {
178167 if(err) throw err
@@ -181,11 +170,10 @@
181170 })
182171 })
183172 })
184173
185-
186174 tape('alice does not replicate messages from bob, but carol does', function (t) {
187-
175 + console.log("**********************************************************")
188176 var friends = 0
189177 carol.friends.get(console.log)
190178 pull(carol.friends.createFriendStream({meta: true, live: true}), pull.drain(function (v) {
191179 friends ++
@@ -195,31 +183,25 @@
195183 cont.para([
196184 cont(alice.publish)(u.follow(carol.id)),
197185 cont(bob.publish)({type:'post', text: 'hello'}),
198186 cont(carol.publish)(u.follow(bob.id))
199- ]) (function () {
187 + ]) (function (err, r) {
200188 var recv = {alice: 0, carol: 0}
201-
202189 carol.post(function (msg) {
203190 recv.carol ++
204191 //will receive one message from bob and carol
205192 }, false)
206193
207194 alice.post(function (msg) {
208195 recv.alice ++
209196 //alice will only receive the message from carol, but not bob.
210- console.log("ALICE_RECV", names[msg.value.author], msg)
211197 t.equal(msg.value.author, carol.id)
212198 }, false)
213199
214- console.log("carol's friends")
215200 carol.friends.get(function (err, g) {
216201 t.ok(g[carol.id][bob.id])
217202 })
218- console.log("alices friends")
219- alice.friends.get(console.log)
220203
221-
222204 var n = 2
223205 carol.connect(alice.getAddress(), cb)
224206 carol.connect(bob.getAddress(), cb)
225207
@@ -232,12 +214,16 @@
232214 pull(
233215 carol.createLogStream(),
234216 pull.collect(function (err, ary) {
235217 if(err) throw err
236- console.log(ary)
237- t.deepEqual(recv, {carol: 2, alice: 2})
238- t.equal(friends, 3, "carol's createFriendStream has 3 peers")
239- t.end()
218 + carol.getVectorClock(function (err, vclock) {
219 + t.equals(vclock[alice.id], 3)
220 + t.equals(vclock[bob.id], 2)
221 + t.equals(vclock[carol.id], 2)
222 +
223 + t.equal(friends, 3, "carol's createFriendStream has 3 peers")
224 + t.end()
225 + })
240226 })
241227 )
242228 }
243229 })
@@ -259,4 +245,21 @@
259245
260246
261247
262248
249 +
250 +
251 +
252 +
253 +
254 +
255 +
256 +
257 +
258 +
259 +
260 +
261 +
262 +
263 +
264 +
265 +
test/block2.jsView
@@ -6,8 +6,9 @@
66
77 var createSbot = require('../')
88 .use(require('../plugins/replicate'))
99 .use(require('ssb-friends'))
10 + .use(require('ssb-ebt'))
1011
1112 var alice = createSbot({
1213 temp: 'test-block-alice', //timeout: 1400,
1314 keys: ssbKeys.generate()
@@ -58,4 +59,6 @@
5859 })
5960
6061
6162
63 +
64 +
test/block3.jsView
@@ -19,8 +19,9 @@
1919
2020 var createSbot = require('../')
2121 .use(require('../plugins/replicate'))
2222 .use(require('ssb-friends'))
23 + .use(require('ssb-ebt'))
2324
2425 var alice = createSbot({
2526 temp: 'test-block-alice', timeout: 1000,
2627 keys: ssbKeys.generate()
@@ -83,4 +84,5 @@
8384
8485
8586
8687
88 +
test/random.jsView
@@ -37,8 +37,9 @@
3737
3838 var createSbot = require('../')
3939 .use(require('../plugins/replicate'))
4040 .use(require('ssb-friends'))
41 + .use(require('ssb-ebt'))
4142 .use(require('../plugins/gossip'))
4243
4344 function generateAnimals (sbot, feed, f, n, cb) {
4445 var a = [feed]
@@ -130,9 +131,9 @@
130131
131132 var animalNetwork = createSbot({
132133 temp: 'test-random-animals',
133134 port: 45451, host: 'localhost', timeout: 20001,
134- replication: {hops: 3}, keys: alice
135 + replication: {hops: 3, legacy: false}, keys: alice
135136 })
136137
137138 pull(
138139 animalNetwork.replicate.changes(),
@@ -234,9 +235,9 @@
234235 var start = Date.now()
235236 var animalFriends = createSbot({
236237 temp: 'test-random-animals2',
237238 port: 45452, host: 'localhost', timeout: 20001,
238- replication: {hops: 3},
239 + replicate: {hops: 3, legacy: false},
239240 progress: true,
240241 seeds: [animalNetwork.getAddress()],
241242 keys: bob
242243 })
@@ -253,25 +254,40 @@
253254 })
254255
255256 var drain
256257
257- pull(
258- animalFriends.replicate.changes(),
259- drain = pull.drain(function (prog) {
260- prog.id = 'animal friends'
258 +// pull(
259 +// animalFriends.replicate.changes(),
260 +// drain = pull.drain(function (prog) {
261 +// prog.id = 'animal friends'
262 +// var target = F+N+3
263 +// process.stdout.write(bar(prog))
264 +// if(prog.progress === target) {
265 +// console.log("DONE!!!!")
266 +// var time = (Date.now() - start) / 1000
267 +// console.log('replicated', target, 'messages in', time, 'at rate',target/time)
268 +// t.equal(c, 1, 'everything replicated within a single connection')
269 +// animalFriends.close(true)
270 +// drain.abort()
271 +// t.end()
272 +// }
273 +// })
274 +// )
275 +
276 + require('../lib/progress')(animalFriends.progress)
277 +
278 + var int = setInterval(function () {
279 + var prog = animalFriends.progress()
280 + if(prog.ebt && prog.ebt.current === prog.ebt.target) {
261281 var target = F+N+3
262- process.stdout.write(bar(prog))
263- if(prog.progress === target) {
264- console.log("DONE!!!!")
265- var time = (Date.now() - start) / 1000
266- console.log('replicated', target, 'messages in', time, 'at rate',target/time)
267- t.equal(c, 1, 'everything replicated within a single connection')
268- animalFriends.close(true)
269- drain.abort()
270- t.end()
271- }
272- })
273- )
282 + var time = (Date.now() - start) / 1000
283 + console.log('replicated', target, 'messages in', time, 'at rate',target/time)
284 + clearInterval(int)
285 + t.equal(c, 1, 'everything replicated within a single connection')
286 + animalFriends.close(true)
287 + t.end()
288 + }
289 + }, 200)
274290
275291 animalFriends.logging = true
276292
277293 if(!animalFriends.friends)
@@ -293,4 +309,9 @@
293309 t.end()
294310 })
295311
296312
313 +
314 +
315 +
316 +
317 +
test/realtime.jsView
@@ -7,22 +7,25 @@
77 var ssbKeys = require('ssb-keys')
88
99 var createSbot = require('../')
1010 .use(require('../plugins/replicate'))
11 + .use(require('ssb-ebt'))
1112 .use(require('ssb-friends'))
1213
1314 tape('replicate between 3 peers', function (t) {
1415
1516 var bob = createSbot({
1617 temp: 'test-bob',
1718 // port: 45452, host: 'localhost',
19 + replicate: {legacy: false},
1820 keys: ssbKeys.generate()
1921 })
2022
2123 var alice = createSbot({
2224 temp: 'test-alice',
2325 // port: 45453, host: 'localhost',
2426 seeds: [bob.getAddress()],
27 + replicate: {legacy: false},
2528 keys: ssbKeys.generate()
2629 })
2730
2831 cont.para([
@@ -68,4 +71,5 @@
6871
6972 })
7073 })
7174
75 +
test/server.jsView
@@ -12,8 +12,9 @@
1212 // and get them to follow each other...
1313
1414 var createSbot = require('../')
1515 .use(require('../plugins/replicate'))
16 +// .use(require('ssb-ebt'))
1617 .use(require('ssb-friends'))
1718 .use(require('../plugins/gossip'))
1819 .use(require('../plugins/logging'))
1920
@@ -23,22 +24,25 @@
2324 var dbA = createSbot({
2425 temp: 'server-alice',
2526 port: 45451, timeout: 1400,
2627 keys: alice = ssbKeys.generate(),
28 + //replicate: {legacy: false},
2729 level: 'info'
2830 })
2931 var dbB = createSbot({
3032 temp: 'server-bob',
3133 port: 45452, timeout: 1400,
3234 keys: bob = ssbKeys.generate(),
3335 seeds: [dbA.getAddress()],
36 + //replicate: {legacy: false},
3437 level: 'info'
3538 })
3639 var dbC = createSbot({
3740 temp: 'server-carol',
3841 port: 45453, timeout: 1400,
3942 keys: carol = ssbKeys.generate(),
4043 seeds: [dbA.getAddress()],
44 + //replicate: {legacy: false},
4145 level: 'info'
4246 })
4347
4448 var apub = cont(dbA.publish)
@@ -89,8 +93,4 @@
8993 }
9094 })
9195 })
9296
93-
94-
95-
96-

Built with git-ssb-web