Files: 3181c169ab56c583d978baa6d19e2c34530706fb / test / timing.js
1703 bytesRaw
1 | |
2 | |
3 | var tape = require('tape') |
4 | |
5 | var util = require('../util') |
6 | var Blobs = require('../') |
7 | |
8 | var pull = require('pull-stream') |
9 | var crypto = require('crypto') |
10 | var rimraf = require('rimraf') |
11 | var path = require('path') |
12 | var osenv = require('osenv') |
13 | |
14 | var dirname = path.join(osenv.tmpdir(), 'test-multiblob') |
15 | rimraf.sync(dirname) |
16 | |
17 | var l = 100, random1 = [] |
18 | while(l --) random1.push(crypto.randomBytes(1024)) |
19 | |
20 | var random2 = random1.slice().reverse() |
21 | var random3 = random1.concat(random2) |
22 | |
23 | |
24 | var blobs = Blobs(dirname) |
25 | |
26 | tape('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 | |
54 | tape('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