Skip to content

Commit

Permalink
Reorder mux test to account for async reads
Browse files Browse the repository at this point in the history
The behaviour of the `'readable'` event changed, or was tightened up,
in

    nodejs/node#17979

such that it is _always_ called on the next tick. This change appears
first in Node.JS v10.0).

Since we rely on `'readable' in the multiplexing, it means that we
have to be more careful about when we wait for the next event loop to
come around in tests.

The tests tend to be much more brittle than live code with respect to
the order things happen, since they attempt to nail down precise
states or orderings (e.g., "the `unpipe` happened exactly between
these writes").
  • Loading branch information
squaremo committed Jul 16, 2018
1 parent 962fb9e commit 8d6594b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions test/mux.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test("single input", function(done) {
var mux = new Mux(output);
mux.pipeFrom(input);

var data = [1,2,3,4,5,6,7,8,9];
var data = [1,2,3,4,5,6,7,8,9];
// not 0, it's treated specially by PassThrough for some reason. By
// 'specially' I mean it breaks the stream. See e.g.,
// https://github.com/isaacs/readable-stream/pull/55
Expand Down Expand Up @@ -112,16 +112,20 @@ test("unpipe", function(done) {

schedule(function() {
pipedData.forEach(input.write.bind(input));
mux.unpipeFrom(input);

schedule(function() {
unpipedData.forEach(input.write.bind(input));
input.end();
mux.unpipeFrom(input);

schedule(function() {
// exhaust so that 'end' fires
var v; while (v = input.read());
unpipedData.forEach(input.write.bind(input));
input.end();
schedule(function() {
// exhaust so that 'end' fires
var v; while (v = input.read());
});
});
});

});

input.on('end', function() {
Expand Down

0 comments on commit 8d6594b

Please sign in to comment.