Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Unified Diff: net/disk_cache/backend_unittest.cc

Issue 2881010: Revert 51456 - Disk cache: Switch the disk cache to use the cache_thread.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/disk_cache_test_base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/backend_unittest.cc
===================================================================
--- net/disk_cache/backend_unittest.cc (revision 51468)
+++ net/disk_cache/backend_unittest.cc (working copy)
@@ -7,6 +7,7 @@
#include "base/path_service.h"
#include "base/platform_thread.h"
#include "base/string_util.h"
+#include "base/thread.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
@@ -253,9 +254,8 @@
EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize));
}
-// Tests that we deal with file-level pending operations at destruction time.
TEST_F(DiskCacheTest, ShutdownWithPendingIO) {
- TestCompletionCallback cb;
+ TestCompletionCallback callback;
{
FilePath path = GetCacheFilePath();
@@ -267,80 +267,33 @@
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb);
- ASSERT_EQ(net::OK, cb.GetResult(rv));
+ cache_thread.message_loop_proxy(), &cache, &callback);
+ ASSERT_EQ(net::OK, callback.GetResult(rv));
- disk_cache::EntryImpl* entry;
- rv = cache->CreateEntry("some key",
- reinterpret_cast<disk_cache::Entry**>(&entry), &cb);
- ASSERT_EQ(net::OK, cb.GetResult(rv));
+ disk_cache::Entry* entry;
+ rv = cache->CreateEntry("some key", &entry, &callback);
+ ASSERT_EQ(net::OK, callback.GetResult(rv));
const int kSize = 25000;
scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize);
CacheTestFillBuffer(buffer->data(), kSize, false);
for (int i = 0; i < 10 * 1024 * 1024; i += 64 * 1024) {
- // We are using the current thread as the cache thread because we want to
- // be able to call directly this method to make sure that the OS (instead
- // of us switching thread) is returning IO pending.
- rv = entry->WriteDataImpl(0, i, buffer, kSize, &cb, false);
+ int rv = entry->WriteData(0, i, buffer, kSize, &callback, false);
if (rv == net::ERR_IO_PENDING)
break;
EXPECT_EQ(kSize, rv);
}
- // Don't call Close() to avoid going through the queue or we'll deadlock
- // waiting for the operation to finish.
- entry->Release();
+ entry->Close();
// The cache destructor will see one pending operation here.
delete cache;
-
- if (rv == net::ERR_IO_PENDING) {
- EXPECT_TRUE(cb.have_result());
- }
}
MessageLoop::current()->RunAllPending();
}
-// Tests that we deal with background-thread pending operations.
-TEST_F(DiskCacheTest, ShutdownWithPendingIO2) {
- 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);
- ASSERT_EQ(net::OK, cb.GetResult(rv));
-
- disk_cache::Entry* entry;
- rv = cache->CreateEntry("some key", &entry, &cb);
- ASSERT_EQ(net::OK, cb.GetResult(rv));
-
- const int kSize = 25000;
- scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize);
- CacheTestFillBuffer(buffer->data(), kSize, false);
-
- rv = entry->WriteData(0, 0, buffer, kSize, &cb, false);
- EXPECT_EQ(net::ERR_IO_PENDING, rv);
-
- entry->Close();
-
- // The cache destructor will see two pending operations here.
- delete cache;
- }
-
- MessageLoop::current()->RunAllPending();
-}
-
TEST_F(DiskCacheTest, TruncatedIndex) {
FilePath path = GetCacheFilePath();
ASSERT_TRUE(DeleteCache(path));
@@ -449,7 +402,6 @@
entries[i]->Doom();
entries[i]->Close();
}
- FlushQueueForTest();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -673,7 +625,6 @@
EXPECT_EQ(2, cache_->GetEntryCount());
SetMaxSize(kSize);
entry->Close(); // Trim the cache.
- FlushQueueForTest();
// If we evicted the entry in less than 20mS, we have one entry in the cache;
// if it took more than that, we posted a task and we'll delete the second
@@ -734,7 +685,6 @@
}
entry->Close(); // Trim the cache.
- FlushQueueForTest();
// We may abort the eviction before cleaning up everything.
MessageLoop::current()->RunAllPending();
@@ -1309,7 +1259,7 @@
EXPECT_EQ(2, cache_->GetEntryCount());
EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
- FlushQueueForTest(); // Allow the restart to finish.
+ MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -1360,8 +1310,7 @@
EXPECT_NE(net::OK, CreateEntry("Something new", &entry2));
entry1->Close();
- FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
- FlushQueueForTest(); // This one actually allows that task to complete.
+ MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -1416,7 +1365,7 @@
ASSERT_LT(count, 9);
};
- FlushQueueForTest();
+ MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, cache_->GetEntryCount());
}
@@ -1465,7 +1414,7 @@
entry1->Close();
EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
- FlushQueueForTest();
+ MessageLoop::current()->RunAllPending();
ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2));
entry2->Close();
@@ -1533,8 +1482,7 @@
entry1->Close();
entry2->Close();
entry3->Close();
- FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
- FlushQueueForTest(); // This one actually allows that task to complete.
+ MessageLoop::current()->RunAllPending();
EXPECT_EQ(0, cache_->GetEntryCount());
}
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/disk_cache_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698