summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/backend_unittest.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 11:32:53 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 11:32:53 +0000
commitc86d350e584b00bd5df71e82b5774ef245a14bef (patch)
treefd28cd57045ae2862e37621e24453612443d8029 /net/disk_cache/backend_unittest.cc
parent0407998a8dbe022e1ae9677935a0bc822bcd61ed (diff)
downloadchromium_src-c86d350e584b00bd5df71e82b5774ef245a14bef.zip
chromium_src-c86d350e584b00bd5df71e82b5774ef245a14bef.tar.gz
chromium_src-c86d350e584b00bd5df71e82b5774ef245a14bef.tar.bz2
GTTF: Make net_unittests run successfully with parallel test launcher
by using a unique directory for disk cache tests. BUG=54098 TEST=run net_unittests using tools/parallel_launcher/parallel_launcher.py Review URL: http://codereview.chromium.org/3410008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/backend_unittest.cc')
-rw-r--r--net/disk_cache/backend_unittest.cc103
1 files changed, 51 insertions, 52 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 3f0018c..7794e51 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -180,11 +180,10 @@ TEST_F(DiskCacheBackendTest, AppCacheKeying) {
}
TEST_F(DiskCacheTest, CreateBackend) {
+ ScopedTestCache test_cache;
TestCompletionCallback cb;
{
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
@@ -192,8 +191,8 @@ TEST_F(DiskCacheTest, CreateBackend) {
// Test the private factory methods.
disk_cache::Backend* cache = NULL;
int rv = disk_cache::BackendImpl::CreateBackend(
- path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), &cache, &cb);
+ test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
+ cache_thread.message_loop_proxy(), &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache);
delete cache;
@@ -204,7 +203,8 @@ TEST_F(DiskCacheTest, CreateBackend) {
cache = NULL;
// Now test the public API.
- rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false,
+ rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, test_cache.path(),
+ 0, false,
cache_thread.message_loop_proxy(),
&cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
@@ -225,7 +225,7 @@ TEST_F(DiskCacheTest, CreateBackend) {
TEST_F(DiskCacheBackendTest, ExternalFiles) {
InitCache();
// First, lets create a file on the folder.
- FilePath filename = GetCacheFilePath().AppendASCII("f_000001");
+ FilePath filename = path().AppendASCII("f_000001");
const int kSize = 50;
scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
@@ -246,19 +246,18 @@ TEST_F(DiskCacheBackendTest, ExternalFiles) {
// Tests that we deal with file-level pending operations at destruction time.
TEST_F(DiskCacheTest, ShutdownWithPendingIO) {
+ ScopedTestCache test_cache;
TestCompletionCallback cb;
{
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
- path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb);
+ test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
+ base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
disk_cache::EntryImpl* entry;
@@ -297,19 +296,18 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO) {
// Tests that we deal with background-thread pending operations.
TEST_F(DiskCacheTest, ShutdownWithPendingIO2) {
+ ScopedTestCache test_cache;
TestCompletionCallback cb;
{
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
- path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), &cache, &cb);
+ test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
+ cache_thread.message_loop_proxy(), &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
disk_cache::Entry* entry;
@@ -333,9 +331,9 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO2) {
}
TEST_F(DiskCacheTest, TruncatedIndex) {
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
- FilePath index = path.AppendASCII("index");
+ ScopedTestCache test_cache;
+
+ FilePath index = test_cache.path().AppendASCII("index");
ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5));
base::Thread cache_thread("CacheThread");
@@ -345,8 +343,8 @@ TEST_F(DiskCacheTest, TruncatedIndex) {
disk_cache::Backend* backend = NULL;
int rv = disk_cache::BackendImpl::CreateBackend(
- path, false, 0, net::DISK_CACHE, disk_cache::kNone,
- cache_thread.message_loop_proxy(), &backend, &cb);
+ test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNone,
+ cache_thread.message_loop_proxy(), &backend, &cb);
ASSERT_NE(net::OK, cb.GetResult(rv));
ASSERT_TRUE(backend == NULL);
@@ -1145,7 +1143,7 @@ TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) {
void DiskCacheBackendTest::BackendTransaction(const std::string& name,
int num_entries, bool load) {
success_ = false;
- ASSERT_TRUE(CopyTestCache(name));
+ ASSERT_TRUE(CopyTestCache(name, path()));
DisableFirstCleanup();
if (load) {
@@ -1176,7 +1174,7 @@ void DiskCacheBackendTest::BackendTransaction(const std::string& name,
cache_ = NULL;
cache_impl_ = NULL;
- ASSERT_TRUE(CheckCacheIntegrity(GetCacheFilePath(), new_eviction_));
+ ASSERT_TRUE(CheckCacheIntegrity(path(), new_eviction_));
success_ = true;
}
@@ -1266,8 +1264,9 @@ TEST_F(DiskCacheBackendTest, NewEvictionRecoverRemove) {
// Tests dealing with cache files that cannot be recovered.
TEST_F(DiskCacheTest, DeleteOld) {
- ASSERT_TRUE(CopyTestCache("wrong_version"));
- FilePath path = GetCacheFilePath();
+ ScopedTestCache test_cache;
+
+ ASSERT_TRUE(CopyTestCache("wrong_version", test_cache.path()));
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
@@ -1275,8 +1274,8 @@ TEST_F(DiskCacheTest, DeleteOld) {
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
- path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), &cache, &cb);
+ test_cache.path(), true, 0, net::DISK_CACHE, disk_cache::kNoRandom,
+ cache_thread.message_loop_proxy(), &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
MessageLoopHelper helper;
@@ -1289,7 +1288,7 @@ TEST_F(DiskCacheTest, DeleteOld) {
// We want to be able to deal with messed up entries on disk.
void DiskCacheBackendTest::BackendInvalidEntry2() {
- ASSERT_TRUE(CopyTestCache("bad_entry"));
+ ASSERT_TRUE(CopyTestCache("bad_entry", path()));
DisableFirstCleanup();
InitCache();
@@ -1313,7 +1312,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) {
// We want to be able to deal with abnormal dirty entries.
void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::string& name) {
- ASSERT_TRUE(CopyTestCache(name));
+ ASSERT_TRUE(CopyTestCache(name, path()));
DisableFirstCleanup();
InitCache();
@@ -1343,8 +1342,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) {
// We want to be able to deal with messed up entries on disk.
void DiskCacheBackendTest::BackendInvalidRankings2() {
- ASSERT_TRUE(CopyTestCache("bad_rankings"));
- FilePath path = GetCacheFilePath();
+ ASSERT_TRUE(CopyTestCache("bad_rankings", path()));
DisableFirstCleanup();
InitCache();
@@ -1380,7 +1378,7 @@ void DiskCacheBackendTest::BackendInvalidRankings() {
}
TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) {
- ASSERT_TRUE(CopyTestCache("bad_rankings"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings", path()));
DisableFirstCleanup();
SetDirectMode();
InitCache();
@@ -1388,7 +1386,7 @@ TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) {
}
TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) {
- ASSERT_TRUE(CopyTestCache("bad_rankings"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings", path()));
DisableFirstCleanup();
SetDirectMode();
SetNewEviction();
@@ -1397,7 +1395,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) {
}
TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) {
- ASSERT_TRUE(CopyTestCache("bad_rankings"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings", path()));
DisableFirstCleanup();
SetDirectMode();
InitCache();
@@ -1406,7 +1404,7 @@ TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) {
}
TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) {
- ASSERT_TRUE(CopyTestCache("bad_rankings"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings", path()));
DisableFirstCleanup();
SetDirectMode();
SetNewEviction();
@@ -1433,7 +1431,7 @@ void DiskCacheBackendTest::BackendDisable() {
}
TEST_F(DiskCacheBackendTest, DisableSuccess) {
- ASSERT_TRUE(CopyTestCache("bad_rankings"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings", path()));
DisableFirstCleanup();
SetDirectMode();
InitCache();
@@ -1441,7 +1439,7 @@ TEST_F(DiskCacheBackendTest, DisableSuccess) {
}
TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) {
- ASSERT_TRUE(CopyTestCache("bad_rankings"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings", path()));
DisableFirstCleanup();
SetDirectMode();
SetNewEviction();
@@ -1450,7 +1448,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) {
}
TEST_F(DiskCacheBackendTest, DisableFailure) {
- ASSERT_TRUE(CopyTestCache("bad_rankings"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings", path()));
DisableFirstCleanup();
SetDirectMode();
InitCache();
@@ -1459,7 +1457,7 @@ TEST_F(DiskCacheBackendTest, DisableFailure) {
}
TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure) {
- ASSERT_TRUE(CopyTestCache("bad_rankings"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings", path()));
DisableFirstCleanup();
SetDirectMode();
SetNewEviction();
@@ -1487,7 +1485,7 @@ void DiskCacheBackendTest::BackendDisable2() {
}
TEST_F(DiskCacheBackendTest, DisableSuccess2) {
- ASSERT_TRUE(CopyTestCache("list_loop"));
+ ASSERT_TRUE(CopyTestCache("list_loop", path()));
DisableFirstCleanup();
SetDirectMode();
InitCache();
@@ -1495,7 +1493,7 @@ TEST_F(DiskCacheBackendTest, DisableSuccess2) {
}
TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) {
- ASSERT_TRUE(CopyTestCache("list_loop"));
+ ASSERT_TRUE(CopyTestCache("list_loop", path()));
DisableFirstCleanup();
SetNewEviction();
SetDirectMode();
@@ -1504,7 +1502,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) {
}
TEST_F(DiskCacheBackendTest, DisableFailure2) {
- ASSERT_TRUE(CopyTestCache("list_loop"));
+ ASSERT_TRUE(CopyTestCache("list_loop", path()));
DisableFirstCleanup();
SetDirectMode();
InitCache();
@@ -1513,7 +1511,7 @@ TEST_F(DiskCacheBackendTest, DisableFailure2) {
}
TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) {
- ASSERT_TRUE(CopyTestCache("list_loop"));
+ ASSERT_TRUE(CopyTestCache("list_loop", path()));
DisableFirstCleanup();
SetDirectMode();
SetNewEviction();
@@ -1540,7 +1538,7 @@ void DiskCacheBackendTest::BackendDisable3() {
}
TEST_F(DiskCacheBackendTest, DisableSuccess3) {
- ASSERT_TRUE(CopyTestCache("bad_rankings2"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings2", path()));
DisableFirstCleanup();
SetMaxSize(20 * 1024 * 1024);
InitCache();
@@ -1548,7 +1546,7 @@ TEST_F(DiskCacheBackendTest, DisableSuccess3) {
}
TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) {
- ASSERT_TRUE(CopyTestCache("bad_rankings2"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings2", path()));
DisableFirstCleanup();
SetMaxSize(20 * 1024 * 1024);
SetNewEviction();
@@ -1606,7 +1604,7 @@ void DiskCacheBackendTest::BackendDisable4() {
}
TEST_F(DiskCacheBackendTest, DisableSuccess4) {
- ASSERT_TRUE(CopyTestCache("bad_rankings"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings", path()));
DisableFirstCleanup();
SetDirectMode();
InitCache();
@@ -1614,7 +1612,7 @@ TEST_F(DiskCacheBackendTest, DisableSuccess4) {
}
TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) {
- ASSERT_TRUE(CopyTestCache("bad_rankings"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings", path()));
DisableFirstCleanup();
SetDirectMode();
SetNewEviction();
@@ -1623,13 +1621,14 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) {
}
TEST_F(DiskCacheTest, Backend_UsageStats) {
+ ScopedTestCache test_cache;
+
MessageLoopHelper helper;
- FilePath path = GetCacheFilePath();
- ASSERT_TRUE(DeleteCache(path));
scoped_ptr<disk_cache::BackendImpl> cache;
cache.reset(new disk_cache::BackendImpl(
- path, base::MessageLoopProxy::CreateForCurrentThread()));
+ test_cache.path(),
+ base::MessageLoopProxy::CreateForCurrentThread()));
ASSERT_TRUE(NULL != cache.get());
cache->SetUnitTestMode();
ASSERT_EQ(net::OK, cache->SyncInit());
@@ -1715,7 +1714,7 @@ void DiskCacheBackendTest::BackendDoomAll2() {
}
TEST_F(DiskCacheBackendTest, DoomAll2) {
- ASSERT_TRUE(CopyTestCache("bad_rankings2"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings2", path()));
DisableFirstCleanup();
SetMaxSize(20 * 1024 * 1024);
InitCache();
@@ -1723,7 +1722,7 @@ TEST_F(DiskCacheBackendTest, DoomAll2) {
}
TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) {
- ASSERT_TRUE(CopyTestCache("bad_rankings2"));
+ ASSERT_TRUE(CopyTestCache("bad_rankings2", path()));
DisableFirstCleanup();
SetMaxSize(20 * 1024 * 1024);
SetNewEviction();
@@ -1735,8 +1734,8 @@ TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) {
// of the cache.
TEST_F(DiskCacheTest, MultipleInstances) {
ScopedTestCache store1;
- ScopedTestCache store2("cache_test2");
- ScopedTestCache store3("cache_test3");
+ ScopedTestCache store2;
+ ScopedTestCache store3;
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));