Commit f759c061511a1a7ccb4677cd693db433280ddacd
Add failing tests for cases discussed in #32
Jan Bölsche committed on 9/12/2015, 4:24:24 PMParent: 8aaed914fd9b931e56aa5467f7f07c9c5f1a9a30
Files changed
test/flatten.js | changed |
test/flatten.js | ||
---|---|---|
@@ -53,20 +53,50 @@ | ||
53 | 53 | |
54 | 54 | }) |
55 | 55 | |
56 | 56 | test('flatten stream of broken streams', function (t) { |
57 | - var _err = new Error('I am broken'); | |
57 | + var _err = new Error('I am broken'), sosEnded | |
58 | 58 | pull( |
59 | 59 | pull.values([ |
60 | 60 | pull.Source(function read(abort, cb) { |
61 | 61 | cb(_err) |
62 | 62 | }) |
63 | - ]), | |
63 | + ], function(err) { | |
64 | + sosEnded = err; | |
65 | + }), | |
64 | 66 | pull.flatten(), |
65 | 67 | pull.onEnd(function (err) { |
66 | 68 | t.equal(err, _err) |
67 | - t.end() | |
69 | + process.nextTick(function() { | |
70 | + t.equal(sosEnded, true, 'should abort stream of streams') | |
71 | + t.end() | |
72 | + }) | |
68 | 73 | }) |
69 | 74 | ) |
75 | +}) | |
70 | 76 | |
77 | +test('abort flatten', function (t) { | |
78 | + var sosEnded, s1Ended, s2Ended | |
79 | + var read = pull( | |
80 | + pull.values([ | |
81 | + pull.values([1,2], function(err) {s1Ended = err}), | |
82 | + pull.values([3,4], function(err) {s2Ended = err}), | |
83 | + ], function(err) { | |
84 | + sosEnded = err; | |
85 | + }), | |
86 | + pull.flatten() | |
87 | + ) | |
88 | + | |
89 | + read(null, function(err, data) { | |
90 | + t.notOk(err) | |
91 | + t.equal(data,1) | |
92 | + read(true, function(err, data) { | |
93 | + t.equal(err, true) | |
94 | + process.nextTick(function() { | |
95 | + t.equal(s1Ended, true, 'should abort current nested stream') | |
96 | + t.equal(s2Ended, undefined, 'should not abort queued nested stream') | |
97 | + t.end() | |
98 | + }) | |
99 | + }) | |
100 | + }) | |
71 | 101 | }) |
72 | 102 |
Built with git-ssb-web