Bugs 715418 and 685804 - Test case for bug 650995 has wrong name / Intermittent failure in test_bug650955.js r=michal.novotny
authorbjarne@runitsoft.com
Mon, 09 Jan 2012 11:02:39 -0500
changeset 86486 c713003d32266feab42364fee8bfb0fa4074337c
parent 86485 8e7225a8b1cc65184cf6a57da336dee5d34fd584
child 86487 cf15bf30ba2cb6c5f1fd0a58e56934f51737b7a5
child 87099 e4828b86cbf773cec53f6a197d076f9fdabeac54
push id674
push userffxbld
push dateTue, 13 Mar 2012 21:17:50 +0000
treeherdermozilla-beta@e3c4c92dec31 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal
bugs715418, 685804, 650995, 650955
milestone12.0a1
first release with
nightly linux32
c713003d3226 / 12.0a1 / 20120110031111 / files
nightly linux64
c713003d3226 / 12.0a1 / 20120110031111 / files
nightly mac
c713003d3226 / 12.0a1 / 20120110031111 / files
nightly win32
c713003d3226 / 12.0a1 / 20120110031111 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
Bugs 715418 and 685804 - Test case for bug 650995 has wrong name / Intermittent failure in test_bug650955.js r=michal.novotny
netwerk/test/unit/test_bug650955.js
netwerk/test/unit/test_bug650995.js
netwerk/test/unit/xpcshell.ini
rename from netwerk/test/unit/test_bug650955.js
rename to netwerk/test/unit/test_bug650995.js
--- a/netwerk/test/unit/test_bug650955.js
+++ b/netwerk/test/unit/test_bug650995.js
@@ -12,21 +12,47 @@ const httpserver = new nsHttpServer();
 
 // Repeats the given data until the total size is larger than 1K
 function repeatToLargerThan1K(data) {
     while(data.length <= 1024)
         data += data;
     return data;
 }
 
+function SyncWithCacheThread(aFunc) {
+  do_check_eq(sync_with_cache_IO_thread_cb.listener, null);
+  sync_with_cache_IO_thread_cb.listener = aFunc;
+
+  var cache = Cc["@mozilla.org/network/cache-service;1"].
+                 getService(Ci.nsICacheService);
+  var session = cache.createSession(
+                  "HTTP",
+                  Ci.nsICache.STORE_ANYWHERE,
+                  Ci.nsICache.STREAM_BASED);
+
+  var cacheEntry = session.asyncOpenCacheEntry(
+                     "nonexistententry",
+                     Ci.nsICache.ACCESS_READ,
+                     sync_with_cache_IO_thread_cb);
+}
+var sync_with_cache_IO_thread_cb = {
+  listener: null,
+
+  onCacheEntryAvailable: function oCEA(descriptor, accessGranted, status) {
+    do_check_neq(status, Cr.NS_OK);
+    cb = this.listener;
+    this.listener = null;
+    do_execute_soon(cb);
+  }
+};
+
 function clearCache() {
     var service = Components.classes["@mozilla.org/network/cache-service;1"]
-        .getService(Components.interfaces.nsICacheService);
-    service.evictEntries(
-        Components.interfaces.nsICache.STORE_ANYWHERE);
+        .getService(Ci.nsICacheService);
+    service.evictEntries(Ci.nsICache.STORE_ANYWHERE);
 }
 
 function setupChannel(suffix, value) {
     var ios = Components.classes["@mozilla.org/network/io-service;1"]
             .getService(Ci.nsIIOService);
     var chan = ios.newChannel("http://localhost:4444" + suffix, "", null);
     var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
     httpChan.setRequestHeader("x-request", value, false);
@@ -54,17 +80,25 @@ var tests = [
                  function() { prefService.setIntPref("browser.cache.disk.max_entry_size", 1); },
                               "0123456789a", "9876543210", "9876543210"), // expect fresh value
              new TestCacheEntrySize(
                  function() { prefService.setIntPref("browser.cache.disk.max_entry_size", -1); },
                               "0123456789a", "9876543210", "0123456789a"), // expect cached value
             ];
 
 function nextTest() {
-    clearCache();
+    // We really want each test to be self-contained. Make sure cache is
+    // cleared and also let all operations finish before starting a new test
+    SyncWithCacheThread(function() {
+        clearCache();
+        SyncWithCacheThread(runNextTest);
+    });
+}
+
+function runNextTest() {
     var aTest = tests.shift();
     if (!aTest) {
         httpserver.stop(do_test_finished);
         return;
     }
     do_execute_soon(function() { aTest.start(); } );
 }
 
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -59,17 +59,17 @@ skip-if = os == "android"
 [test_bug553970.js]
 [test_bug561042.js]
 [test_bug561276.js]
 [test_bug580508.js]
 [test_bug586908.js]
 [test_bug596443.js]
 [test_bug618835.js]
 [test_bug633743.js]
-[test_bug650955.js]
+[test_bug650995.js]
 [test_bug652761.js]
 [test_bug651100.js]
 # Bug 675044: test fails consistently on Android
 fail-if = os == "android"  
 [test_bug654926.js]
 # Bug 675049: test fails consistently on Android
 fail-if = os == "android"  
 [test_bug654926_doom_and_read.js]