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