Commit 784f930c authored by jam@chromium.org's avatar jam@chromium.org

Run the disk cache tests in scoped temporary directories instead of a fixed...

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
parent e529d9f1
...@@ -2356,9 +2356,10 @@ TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) { ...@@ -2356,9 +2356,10 @@ TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) {
// We should be able to create the same entry on multiple simultaneous instances // We should be able to create the same entry on multiple simultaneous instances
// of the cache. // of the cache.
TEST_F(DiskCacheTest, MultipleInstances) { TEST_F(DiskCacheTest, MultipleInstances) {
ScopedTestCache store1(cache_path_); ScopedTempDir store1, store2;
ScopedTestCache store2("cache_test2"); ASSERT_TRUE(store1.CreateUniqueTempDir());
ScopedTestCache store3("cache_test3"); ASSERT_TRUE(store2.CreateUniqueTempDir());
base::Thread cache_thread("CacheThread"); base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions( ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0))); base::Thread::Options(MessageLoop::TYPE_IO, 0)));
......
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
#include "net/disk_cache/mem_backend_impl.h" #include "net/disk_cache/mem_backend_impl.h"
DiskCacheTest::DiskCacheTest() { DiskCacheTest::DiskCacheTest() {
cache_path_ = GetCacheFilePath(); CHECK(temp_dir_.CreateUniqueTempDir());
cache_path_ = temp_dir_.path();
if (!MessageLoop::current()) if (!MessageLoop::current())
message_loop_.reset(new MessageLoopForIO()); message_loop_.reset(new MessageLoopForIO());
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/scoped_temp_dir.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "net/base/cache_type.h" #include "net/base/cache_type.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -48,6 +49,7 @@ class DiskCacheTest : public PlatformTest { ...@@ -48,6 +49,7 @@ class DiskCacheTest : public PlatformTest {
FilePath cache_path_; FilePath cache_path_;
private: private:
ScopedTempDir temp_dir_;
scoped_ptr<MessageLoop> message_loop_; scoped_ptr<MessageLoop> message_loop_;
}; };
......
...@@ -16,20 +16,6 @@ ...@@ -16,20 +16,6 @@
using base::Time; using base::Time;
using base::TimeDelta; 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) { std::string GenerateKey(bool same_length) {
char key[200]; char key[200];
CacheTestFillBuffer(key, sizeof(key), same_length); CacheTestFillBuffer(key, sizeof(key), same_length);
...@@ -55,10 +41,6 @@ void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls) { ...@@ -55,10 +41,6 @@ void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls) {
buffer[0] = 'g'; buffer[0] = 'g';
} }
FilePath GetCacheFilePath() {
return BuildCachePath("cache_test");
}
bool CreateCacheTestFile(const FilePath& name) { bool CreateCacheTestFile(const FilePath& name) {
int flags = base::PLATFORM_FILE_CREATE_ALWAYS | int flags = base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_READ | base::PLATFORM_FILE_READ |
...@@ -91,21 +73,6 @@ bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask) { ...@@ -91,21 +73,6 @@ bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask) {
return cache->SelfCheck() >= 0; 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() MessageLoopHelper::MessageLoopHelper()
......
...@@ -19,9 +19,6 @@ bool CreateCacheTestFile(const FilePath& name); ...@@ -19,9 +19,6 @@ bool CreateCacheTestFile(const FilePath& name);
// Deletes all file son the cache. // Deletes all file son the cache.
bool DeleteCache(const FilePath& path); 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). // Fills buffer with random values (may contain nulls unless no_nulls is true).
void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls); void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls);
...@@ -31,23 +28,6 @@ std::string GenerateKey(bool same_length); ...@@ -31,23 +28,6 @@ std::string GenerateKey(bool same_length);
// Returns true if the cache is not corrupt. // Returns true if the cache is not corrupt.
bool CheckCacheIntegrity(const FilePath& path, bool new_eviction, uint32 mask); 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. // Simple helper to deal with the message loop on a test.
......
...@@ -101,7 +101,10 @@ std::string GenerateStressKey() { ...@@ -101,7 +101,10 @@ std::string GenerateStressKey() {
void StressTheCache(int iteration) { void StressTheCache(int iteration) {
int cache_size = 0x2000000; // 32MB. int cache_size = 0x2000000; // 32MB.
uint32 mask = 0xfff; // 4096 entries. 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"); base::Thread cache_thread("CacheThread");
if (!cache_thread.StartWithOptions( if (!cache_thread.StartWithOptions(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment