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) {
// 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)));
......
......@@ -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());
}
......
......@@ -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_;
};
......
......@@ -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()
......
......@@ -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.
......
......@@ -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(
......
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