From d006a61f174ef4c52d42a17b6e33af01e2744f5c Mon Sep 17 00:00:00 2001 From: "bjarne@runitsoft.com" Date: Mon, 9 Jan 2012 11:02:39 -0500 Subject: [PATCH] Bugs 715418 and 685804 - Test case for bug 650995 has wrong name / Intermittent failure in test_bug650955.js r=michal.novotny --HG-- rename : netwerk/test/unit/test_bug650955.js => netwerk/test/unit/test_bug650995.js --- .../{test_bug650955.js => test_bug650995.js} | 42 +++++++++++++++++-- netwerk/test/unit/xpcshell.ini | 2 +- 2 files changed, 39 insertions(+), 5 deletions(-) rename netwerk/test/unit/{test_bug650955.js => test_bug650995.js} (82%) diff --git a/netwerk/test/unit/test_bug650955.js b/netwerk/test/unit/test_bug650995.js similarity index 82% rename from netwerk/test/unit/test_bug650955.js rename to netwerk/test/unit/test_bug650995.js index 9d4d533d01c..9c8dbbe4a39 100644 --- a/netwerk/test/unit/test_bug650955.js +++ b/netwerk/test/unit/test_bug650995.js @@ -17,11 +17,37 @@ function repeatToLargerThan1K(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) { @@ -59,7 +85,15 @@ var tests = [ ]; 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); diff --git a/netwerk/test/unit/xpcshell.ini b/netwerk/test/unit/xpcshell.ini index 00ef9b49e6e..2920ac9b916 100644 --- a/netwerk/test/unit/xpcshell.ini +++ b/netwerk/test/unit/xpcshell.ini @@ -64,7 +64,7 @@ skip-if = os == "android" [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