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 315845 916c47f534c20427eecbb988453fe2e32004d4c4
parent 315844 3caff20982f80d8649e8c399c3a392a0b623c813
child 315846 e1300d4c0a52c8b9697cb50b96f62b89e0507544
push id82294
push usermaglione.k@gmail.com
push dateThu, 29 Sep 2016 23:07:56 +0000
treeherdermozilla-inbound@916c47f534c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1295867
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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));
+  });
 }