commit 4145b1c18762a46af04be129aec48eed30754956 Author: Tom Hughes Date: Thu Dec 31 12:18:02 2015 +0000 Wait until the next tick to pause the stream Registering handlers on a stream with `on` causes resume to be called, but only on the next tick. This leads to a race condition where the pause can happen before that delayed resume, which then resumes the stream earlier than we were expecting. diff --git a/test/readdirp-stream.js b/test/readdirp-stream.js index c43d132..e45bab5 100644 --- a/test/readdirp-stream.js +++ b/test/readdirp-stream.js @@ -252,16 +252,19 @@ test('\napi separately', function (t) { t.equals(data, processedData, 'emits the buffered data'); t.ok(resumed, 'emits data only after it was resumed'); }) - .pause() - api.processEntry(processedData); - api.handleError(nonfatalError); - api.handleFatalError(fatalError); + process.nextTick(function() { + api.stream.pause(); + + api.processEntry(processedData); + api.handleError(nonfatalError); + api.handleFatalError(fatalError); - setTimeout(function () { - resumed = true; - api.stream.resume(); - }, 1) + setTimeout(function () { + resumed = true; + api.stream.resume(); + }, 1) + }) }) t.test('\n# when a stream is paused it stops walking the fs', function (t) {