Chromium Code Reviews| Index: net/disk_cache/backend_unittest.cc |
| =================================================================== |
| --- net/disk_cache/backend_unittest.cc (revision 126788) |
| +++ net/disk_cache/backend_unittest.cc (working copy) |
| @@ -35,6 +35,9 @@ |
| protected: |
| void BackendBasics(); |
| void BackendKeying(); |
| + void BackendShutdownWithPendingIO(bool wait); |
| + void BackendShutdownWithPendingIO2(bool wait); |
| + void BackendShutdownWithPendingIO3(bool wait); |
| void BackendSetSize(); |
| void BackendLoad(); |
| void BackendChain(); |
| @@ -275,7 +278,7 @@ |
| } |
| // Tests that we deal with file-level pending operations at destruction time. |
| -TEST_F(DiskCacheTest, ShutdownWithPendingIO) { |
| +void DiskCacheBackendTest::BackendShutdownWithPendingIO(bool wait) { |
|
gavinp
2012/03/18 00:35:26
A single bool argument at a call site can be confu
gavinp
2012/03/18 00:35:26
How about calling this BackendShutdownWithPendingC
|
| net::TestCompletionCallback cb; |
| { |
| @@ -285,8 +288,10 @@ |
| base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| disk_cache::Backend* cache; |
| + uint32 flags = wait ? disk_cache::kNoRandom : disk_cache::kNone; |
|
gavinp
2012/03/18 00:35:26
uint32 flags = disk_cache::kNoBuffering;
if (pendi
|
| + flags |= disk_cache::kNoBuffering; |
| int rv = disk_cache::BackendImpl::CreateBackend( |
| - cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
| + cache_path_, false, 0, net::DISK_CACHE, flags, |
| base::MessageLoopProxy::current(), NULL, |
| &cache, cb.callback()); |
| ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| @@ -319,15 +324,32 @@ |
| delete cache; |
| if (rv == net::ERR_IO_PENDING) { |
| - EXPECT_TRUE(cb.have_result()); |
| + if (wait) { |
|
gavinp
2012/03/18 00:35:26
Take it or leave it nit: I favour no braces in thi
|
| + EXPECT_TRUE(cb.have_result()); |
| + } else { |
| + EXPECT_FALSE(cb.have_result()); |
| + } |
| } |
| } |
| MessageLoop::current()->RunAllPending(); |
| } |
| +TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO) { |
| + // Do full synchronization at destruction. |
| + BackendShutdownWithPendingIO(true); |
| +} |
| + |
| +TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO_Fast) { |
| + // The integrity test sets kNoRandom so there's a version mismatch if we don't |
| + // force new eviction. |
| + SetNewEviction(); |
| + // Do minimal synchronization at destruction. |
| + BackendShutdownWithPendingIO(false); |
| +} |
| + |
| // Tests that we deal with background-thread pending operations. |
| -TEST_F(DiskCacheTest, ShutdownWithPendingIO2) { |
| +void DiskCacheBackendTest::BackendShutdownWithPendingIO2(bool wait) { |
|
gavinp
2012/03/18 00:35:26
How about BackendShutdownWithPendingWrites() ???
|
| net::TestCompletionCallback cb; |
| { |
| @@ -337,8 +359,10 @@ |
| base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| disk_cache::Backend* cache; |
| + uint32 flags = wait ? disk_cache::kNoRandom : disk_cache::kNone; |
| + flags |= disk_cache::kNoBuffering; |
| int rv = disk_cache::BackendImpl::CreateBackend( |
| - cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
| + cache_path_, false, 0, net::DISK_CACHE, flags, |
| cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); |
| ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| @@ -362,6 +386,62 @@ |
| MessageLoop::current()->RunAllPending(); |
| } |
| +TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO2) { |
| + // Do full synchronization at destruction. |
| + BackendShutdownWithPendingIO2(true); |
| +} |
| + |
| +TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO2_Fast) { |
| + // The integrity test sets kNoRandom so there's a version mismatch if we don't |
| + // force new eviction. |
| + SetNewEviction(); |
| + // Do minimal synchronization at destruction. |
| + BackendShutdownWithPendingIO2(false); |
| +} |
| + |
| +// Tests that we deal with create-type pending operations. |
| +void DiskCacheBackendTest::BackendShutdownWithPendingIO3(bool wait) { |
|
gavinp
2012/03/18 00:35:26
BackendShutdownWithPendingBufferedCreates ?
|
| + net::TestCompletionCallback cb; |
| + |
| + { |
| + ASSERT_TRUE(CleanupCacheDir()); |
| + base::Thread cache_thread("CacheThread"); |
| + ASSERT_TRUE(cache_thread.StartWithOptions( |
| + base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| + |
| + disk_cache::Backend* cache; |
| + disk_cache::BackendFlags flags = |
| + wait ? disk_cache::kNoRandom : disk_cache::kNone; |
| + int rv = disk_cache::BackendImpl::CreateBackend( |
| + cache_path_, false, 0, net::DISK_CACHE, flags, |
| + cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); |
| + ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| + |
| + disk_cache::Entry* entry; |
| + rv = cache->CreateEntry("some key", &entry, cb.callback()); |
| + ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| + |
| + delete cache; |
| + EXPECT_FALSE(cb.have_result()); |
| + } |
| + |
| + MessageLoop::current()->RunAllPending(); |
| +} |
| + |
| +TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO3) { |
| + // Do full synchronization at destruction. |
| + BackendShutdownWithPendingIO3(true); |
| +} |
| + |
| +// We'll be leaking an entry from this test. |
| +TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO3_Fast) { |
| + // The integrity test sets kNoRandom so there's a version mismatch if we don't |
| + // force new eviction. |
| + SetNewEviction(); |
| + // Do minimal synchronization at destruction. |
| + BackendShutdownWithPendingIO3(false); |
| +} |
| + |
| TEST_F(DiskCacheTest, TruncatedIndex) { |
| ASSERT_TRUE(CleanupCacheDir()); |
| FilePath index = cache_path_.AppendASCII("index"); |