git ssb

0+

cryptop / multiblob



forked from Dominic / multiblob

Tree: 3181c169ab56c583d978baa6d19e2c34530706fb

Files: 3181c169ab56c583d978baa6d19e2c34530706fb / test / timing.js

1703 bytesRaw
1
2
3var tape = require('tape')
4
5var util = require('../util')
6var Blobs = require('../')
7
8var pull = require('pull-stream')
9var crypto = require('crypto')
10var rimraf = require('rimraf')
11var path = require('path')
12var osenv = require('osenv')
13
14var dirname = path.join(osenv.tmpdir(), 'test-multiblob')
15rimraf.sync(dirname)
16
17var l = 100, random1 = []
18while(l --) random1.push(crypto.randomBytes(1024))
19
20var random2 = random1.slice().reverse()
21var random3 = random1.concat(random2)
22
23
24var blobs = Blobs(dirname)
25
26tape('live stream triggers same tick (just before callback)', function (t) {
27
28 var live = false
29
30 pull(
31 blobs.ls({live: true}),
32 pull.drain(function (data) {
33 console.log('stream1', data)
34 if(data.sync) return next()
35 if(live) throw new Error('live stream called twice!')
36 live = true
37 console.log(data)
38 return false
39 })
40 )
41
42 function next () {
43 pull(
44 pull.values(random1),
45 blobs.add(function (err, _hash) {
46 if(err) throw err
47 t.ok(live)
48 t.end()
49 })
50 )
51 }
52})
53
54tape('live stream triggers same tick (just before callback)', function (t) {
55 //return t.end()
56 var live = false, sync = false
57 pull(
58 blobs.ls({live: true, long: true}),
59 pull.drain(function (data) {
60 if(data.sync) return next(sync = true)
61 if(!sync) return
62
63 console.log('stream2', data)
64 if(live) throw new Error('live stream 2 called twice!')
65 live = true
66 })
67 )
68
69 function next () {
70 pull(
71 pull.values(random2),
72 blobs.add(function (err, _hash) {
73 console.log('ADDED random2')
74 if(err) throw err
75 t.ok(live)
76 t.end()
77 })
78 )
79 }
80})
81
82

Built with git-ssb-web