diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-17 00:13:43 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-17 00:13:43 +0000 |
commit | 784f930c48a22afae7e94778419e2ee9863f1814 (patch) | |
tree | 11b8c86a33c9e10c1c6832a122821e88a91297f6 | |
parent | e529d9f155fde4d6bbf2e69d2d7b0482c5971ca9 (diff) | |
download | chromium_src-784f930c48a22afae7e94778419e2ee9863f1814.zip chromium_src-784f930c48a22afae7e94778419e2ee9863f1814.tar.gz chromium_src-784f930c48a22afae7e94778419e2ee9863f1814.tar.bz2 |
Run the disk cache tests in scoped temporary directories instead of a fixed directory so that they can run in parallel.
BUG=139272
Review URL: https://chromiumcodereview.appspot.com/10824336
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151999 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 7 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_base.cc | 3 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_base.h | 2 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.cc | 33 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.h | 20 | ||||
-rw-r--r-- | net/disk_cache/stress_cache.cc | 5 |
6 files changed, 12 insertions, 58 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index 78a5777..b6fa920 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -2356,9 +2356,10 @@ TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) { // We should be able to create the same entry on multiple simultaneous instances // of the cache. TEST_F(DiskCacheTest, MultipleInstances) { - ScopedTestCache store1(cache_path_); - ScopedTestCache store2("cache_test2"); - ScopedTestCache store3("cache_test3"); + ScopedTempDir store1, store2; + ASSERT_TRUE(store1.CreateUniqueTempDir()); + ASSERT_TRUE(store2.CreateUniqueTempDir()); + base::Thread cache_thread("CacheThread"); ASSERT_TRUE(cache_thread.StartWithOptions( base::Thread::Options(MessageLoop::TYPE_IO, 0))); diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc index 5ed2f90..608b729 100644 --- a/net/disk_cache/disk_cache_test_base.cc +++ b/net/disk_cache/disk_cache_test_base.cc @@ -14,7 +14,8 @@ #include "net/disk_cache/mem_backend_impl.h" DiskCacheTest::DiskCacheTest() { - cache_path_ = GetCacheFilePath(); + CHECK(temp_dir_.CreateUniqueTempDir()); + cache_path_ = temp_dir_.path(); if (!MessageLoop::current()) message_loop_.reset(new MessageLoopForIO()); } diff --git a/net/disk_cache/disk_cache_test_base.h b/net/disk_cache/disk_cache_test_base.h index b5bd459..03a9a72 100644 --- a/net/disk_cache/disk_cache_test_base.h +++ b/net/disk_cache/disk_cache_test_base.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/file_path.h" #include "base/memory/scoped_ptr.h" +#include "base/scoped_temp_dir.h" #include "base/threading/thread.h" #include "net/base/cache_type.h" #include "testing/gtest/include/gtest/gtest.h" @@ -48,6 +49,7 @@ class DiskCacheTest : public PlatformTest { FilePath cache_path_; private: + ScopedTempDir temp_dir_; scoped_ptr<MessageLoop> message_loop_; }; diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc index 3986591..dce005e 100644 --- a/net/disk_cache/disk_cache_test_util.cc +++ b/net/disk_cache/disk_cache_test_util.cc @@ -16,20 +16,6 @@ using base::Time; using base::TimeDelta; -namespace { - -FilePath BuildCachePath(const std::string& name) { - FilePath path; - PathService::Get(base::DIR_TEMP, &path); // Ignore return value; - path = path.AppendASCII(name); - if (!file_util::PathExists(path)) - file_util::CreateDirectory(path); - - return path; -} - -} // namespace. - std::string GenerateKey(bool same_length) { char key[200]; CacheTestFillBuffer(key, sizeof(key), same_length); @@ -55,10 +41,6 @@ void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls) { buffer[0] = 'g'; } -FilePath GetCacheFilePath() { - return BuildCachePath("cache_test"); -} - bool CreateCacheTestFile(const FilePath& name) { int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_READ | @@ -91,21 +73,6 @@ bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask) { return cache->SelfCheck() >= 0; } -ScopedTestCache::ScopedTestCache(const FilePath& path) : path_(path) { - bool result = DeleteCache(path_); - DCHECK(result); -} - -ScopedTestCache::ScopedTestCache(const std::string& name) - : path_(BuildCachePath(name)) { - bool result = DeleteCache(path_); - DCHECK(result); -} - -ScopedTestCache::~ScopedTestCache() { - file_util::Delete(path(), true); -} - // ----------------------------------------------------------------------- MessageLoopHelper::MessageLoopHelper() diff --git a/net/disk_cache/disk_cache_test_util.h b/net/disk_cache/disk_cache_test_util.h index 2194561..80c8a7e 100644 --- a/net/disk_cache/disk_cache_test_util.h +++ b/net/disk_cache/disk_cache_test_util.h @@ -19,9 +19,6 @@ bool CreateCacheTestFile(const FilePath& name); // Deletes all file son the cache. bool DeleteCache(const FilePath& path); -// Gets the path to the cache test folder. -FilePath GetCacheFilePath(); - // Fills buffer with random values (may contain nulls unless no_nulls is true). void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls); @@ -31,23 +28,6 @@ std::string GenerateKey(bool same_length); // Returns true if the cache is not corrupt. bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask); -// Helper class which ensures that the cache dir returned by GetCacheFilePath -// exists and is clear in ctor and that the directory gets deleted in dtor. -class ScopedTestCache { - public: - explicit ScopedTestCache(const FilePath& path); - // Use a specific folder name. - explicit ScopedTestCache(const std::string& name); - ~ScopedTestCache(); - - FilePath path() const { return path_; } - - private: - const FilePath path_; // Path to the cache test folder. - - DISALLOW_COPY_AND_ASSIGN(ScopedTestCache); -}; - // ----------------------------------------------------------------------- // Simple helper to deal with the message loop on a test. diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc index 56e1346..20f63c3 100644 --- a/net/disk_cache/stress_cache.cc +++ b/net/disk_cache/stress_cache.cc @@ -101,7 +101,10 @@ std::string GenerateStressKey() { void StressTheCache(int iteration) { int cache_size = 0x2000000; // 32MB. uint32 mask = 0xfff; // 4096 entries. - FilePath path = GetCacheFilePath().InsertBeforeExtensionASCII("_stress"); + + FilePath path; + PathService::Get(base::DIR_TEMP, &path); + path = path.AppendASCII("cache_test_stress"); base::Thread cache_thread("CacheThread"); if (!cache_thread.StartWithOptions( |