Bug 1295867: Fix race in handling buffered stderr output from native app. r=me
authorKris Maglione <maglione.k@gmail.com>
Fri, 30 Sep 2016 00:06:42 +0100
changeset 315931 916c47f534c20427eecbb988453fe2e32004d4c4
parent 315930 3caff20982f80d8649e8c399c3a392a0b623c813
child 315932 e1300d4c0a52c8b9697cb50b96f62b89e0507544
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1295867
milestone52.0a1
Bug 1295867: Fix race in handling buffered stderr output from native app. r=me MozReview-Commit-ID: 14wEDVGlRyb
toolkit/components/extensions/test/xpcshell/head_native_messaging.js
--- a/toolkit/components/extensions/test/xpcshell/head_native_messaging.js
+++ b/toolkit/components/extensions/test/xpcshell/head_native_messaging.js
@@ -4,16 +4,18 @@
 
 /* globals AppConstants, FileUtils */
 /* exported getSubprocessCount, setupHosts, waitForSubprocessExit */
 
 XPCOMUtils.defineLazyModuleGetter(this, "MockRegistry",
                                   "resource://testing-common/MockRegistry.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "OS",
                                   "resource://gre/modules/osfile.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "setTimeout",
+                                  "resource://gre/modules/Timer.jsm");
 
 let {Subprocess, SubprocessImpl} = Cu.import("resource://gre/modules/Subprocess.jsm");
 
 
 let tmpDir = FileUtils.getDir("TmpD", ["NativeMessaging"]);
 tmpDir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
 
 do_register_cleanup(() => {
@@ -112,10 +114,14 @@ function* setupHosts(scripts) {
 }
 
 
 function getSubprocessCount() {
   return SubprocessImpl.Process.getWorker().call("getProcesses", [])
                        .then(result => result.size);
 }
 function waitForSubprocessExit() {
-  return SubprocessImpl.Process.getWorker().call("waitForNoProcesses", []);
+  return SubprocessImpl.Process.getWorker().call("waitForNoProcesses", []).then(() => {
+    // Return to the main event loop to give IO handlers enough time to consume
+    // their remaining buffered input.
+    return new Promise(resolve => setTimeout(resolve, 0));
+  });
 }