Bug 1493807 - Wait for crash reporter dump file to become unlocked before deleting it in test-plugin-crashing.js. r=jorgk
authoraceman <acelists@atlas.sk>
Tue, 25 Sep 2018 01:14:43 +0200
changeset 33223 ed39f537696876ed0a5a9304cf94d40621131e61
parent 33222 06e1ec5ea2586ef807f966e8450346603c37f4f8
child 33224 c695d2d8148c025254be5eab83310bf21490d418
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1493807
Bug 1493807 - Wait for crash reporter dump file to become unlocked before deleting it in test-plugin-crashing.js. r=jorgk
mail/test/mozmill/content-tabs/test-plugin-crashing.js
--- a/mail/test/mozmill/content-tabs/test-plugin-crashing.js
+++ b/mail/test/mozmill/content-tabs/test-plugin-crashing.js
@@ -128,18 +128,17 @@ var PluginCrashObserver = {
     Services.obs.removeObserver(this, "plugin-crashed");
   },
 
   observe: function(aSubject, aTopic, aData) {
     if (aTopic != "plugin-crashed")
       return;
 
     try {
-      this.removeMinidump(
-        aSubject.QueryInterface(Ci.nsIPropertyBag2));
+      this.removeMinidump(aSubject.QueryInterface(Ci.nsIPropertyBag2));
     } catch (ex) {
       Cu.reportError(ex);
       frame.events.fail({exception: ex, test: frame.events.currentTest});
     }
   },
 
   removeMinidump: function PluginCrashObserver_removeMinidump(aPropBag) {
     this._sawCrash = true;
@@ -150,21 +149,42 @@ var PluginCrashObserver = {
     // Let's check to see if a minidump was created.  If so, delete
     // it (along with the .extra file)
     let crashId = aPropBag.getPropertyAsAString("pluginDumpID");
     let dumpFile = profD.clone();
     dumpFile.append(crashId + ".dmp");
     let extraFile = profD.clone();
     extraFile.append(crashId + ".extra");
 
+    // Retry deletion until crash reporter releases the file.
+    function remove_locked_file(aFile) {
+      function try_removal(aFile) {
+        try {
+          // Yield to the event loop while waiting for the file to get unlocked.
+          mc.sleep(0);
+          aFile.remove(false);
+        } catch (e) {
+          if (e.result == Cr.NS_ERROR_FILE_IS_LOCKED)
+            return false;
+
+          throw e;
+        }
+        return true;
+      }
+
+      mc.waitFor(() => try_removal(aFile) === true,
+                 `File ${aFile.leafName} couldn't be removed due to a lock`, 20000, 250);
+      assert_false(aFile.exists());
+    }
+
     if (dumpFile.exists())
-      dumpFile.remove(false);
+      remove_locked_file(dumpFile);
 
     if (extraFile.exists())
-      extraFile.remove(false);
+      remove_locked_file(extraFile);
   }
 }
 
 /* Crash the plugin */
 function crash_plugin() {
   try {
     let plugin = gTabDoc.getElementById(kPluginId);
     PluginCrashObserver.planForCrash(mc);