Bug 844392 - Fix race condition where ProcessStateChange can remove a file before cleanup. r=paolo
authorMonica Chew <mmc@mozilla.com>
Thu, 07 Mar 2013 08:35:38 -0500
changeset 124107 99ef1303095d41f4bb647fcb0e318cef22d42d3b
parent 124106 fc9cdf372502878c8da412c6d50c2a0f0f80c13b
child 124108 814a0c94b2157293a978dd976273c28e9fb304b6
push id24406
push userryanvm@gmail.com
push dateThu, 07 Mar 2013 17:19:02 +0000
treeherdermozilla-central@71395a927025 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo
bugs844392
milestone22.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 844392 - Fix race condition where ProcessStateChange can remove a file before cleanup. r=paolo
netwerk/test/unit/test_backgroundfilesaver.js
--- a/netwerk/test/unit/test_backgroundfilesaver.js
+++ b/netwerk/test/unit/test_backgroundfilesaver.js
@@ -466,32 +466,39 @@ add_task(function test_finish_only()
   let completionPromise = promiseSaverComplete(saver, onTargetChange);
   saver.finish(Cr.NS_OK);
   yield completionPromise;
 });
 
 add_task(function test_invalid_hash()
 {
   let saver = new BackgroundFileSaverStreamListener();
+  let completionPromise = promiseSaverComplete(saver);
   // We shouldn't be able to get the hash if hashing hasn't been enabled
   try {
     let hash = saver.sha256Hash;
-    throw "Shouldn't be able to get hash if hashing not enabled";
+    do_throw("Shouldn't be able to get hash if hashing not enabled");
   } catch (ex if ex.result == Cr.NS_ERROR_NOT_AVAILABLE) { }
   // Enable hashing, but don't feed any data to saver
   saver.enableSha256();
   let destFile = getTempFile(TEST_FILE_NAME_1);
   saver.setTarget(destFile, false);
   // We don't wait on promiseSaverComplete, so the hash getter can run before
   // or after onSaveComplete is called. However, the expected behavior is the
   // same in both cases since the hash is only valid when the save completes
   // successfully.
   saver.finish(Cr.NS_ERROR_FAILURE);
   try {
     let hash = saver.sha256Hash;
-    throw "Shouldn't be able to get hash if save did not succeed";
+    do_throw("Shouldn't be able to get hash if save did not succeed");
   } catch (ex if ex.result == Cr.NS_ERROR_NOT_AVAILABLE) { }
+  // Wait for completion so that the worker thread finishes dealing with the
+  // target file. We expect it to fail.
+  try {
+    yield completionPromise;
+    do_throw("completionPromise should throw");
+  } catch (ex if ex.result == Cr.NS_ERROR_FAILURE) { }
 });
 
 add_task(function test_teardown()
 {
   gStillRunning = false;
 });