diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-13 18:00:56 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-13 18:00:56 +0000 |
commit | fb2622f6816ed20ffd8a35994f7372b67613ba92 (patch) | |
tree | 2aa33016e72361032264904916c4374e4784fd11 /net/disk_cache/entry_unittest.cc | |
parent | ea9a4ee67732b90e834def1cf98be1d047a93063 (diff) | |
download | chromium_src-fb2622f6816ed20ffd8a35994f7372b67613ba92.zip chromium_src-fb2622f6816ed20ffd8a35994f7372b67613ba92.tar.gz chromium_src-fb2622f6816ed20ffd8a35994f7372b67613ba92.tar.bz2 |
Disk cache: Switch the disk cache to use the cache_thread.
Add an InFlightBackendIO class that handles posting of
cacheoperations back and forth between the IO thread and
the cachethread.
BUG=26730
TEST=unit tests
Review URL: http://codereview.chromium.org/2945002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52185 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/entry_unittest.cc')
-rw-r--r-- | net/disk_cache/entry_unittest.cc | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc index 95bbb47..067f260 100644 --- a/net/disk_cache/entry_unittest.cc +++ b/net/disk_cache/entry_unittest.cc @@ -82,10 +82,12 @@ void DiskCacheEntryTest::InternalSyncIO() { entry1->Doom(); entry1->Close(); + FlushQueueForTest(); EXPECT_EQ(0, cache_->GetEntryCount()); } TEST_F(DiskCacheEntryTest, InternalSyncIO) { + SetDirectMode(); InitCache(); InternalSyncIO(); } @@ -223,10 +225,12 @@ void DiskCacheEntryTest::InternalAsyncIO() { entry1->Doom(); entry1->Close(); + FlushQueueForTest(); EXPECT_EQ(0, cache_->GetEntryCount()); } TEST_F(DiskCacheEntryTest, InternalAsyncIO) { + SetDirectMode(); InitCache(); InternalAsyncIO(); } @@ -269,10 +273,12 @@ void DiskCacheEntryTest::ExternalSyncIO() { entry1->Doom(); entry1->Close(); + FlushQueueForTest(); EXPECT_EQ(0, cache_->GetEntryCount()); } TEST_F(DiskCacheEntryTest, ExternalSyncIO) { + SetDirectMode(); InitCache(); ExternalSyncIO(); } @@ -367,19 +373,21 @@ void DiskCacheEntryTest::ExternalAsyncIO() { EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret); if (net::ERR_IO_PENDING == ret) expected++; - EXPECT_EQ(37000, entry1->GetDataSize(1)); EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); + EXPECT_EQ(37000, entry1->GetDataSize(1)); EXPECT_FALSE(g_cache_tests_error); EXPECT_EQ(expected, g_cache_tests_received); entry1->Doom(); entry1->Close(); + FlushQueueForTest(); EXPECT_EQ(0, cache_->GetEntryCount()); } TEST_F(DiskCacheEntryTest, ExternalAsyncIO) { + SetDirectMode(); InitCache(); ExternalAsyncIO(); } @@ -788,10 +796,12 @@ void DiskCacheEntryTest::DoomNormalEntry() { entry1->Doom(); entry1->Close(); + FlushQueueForTest(); EXPECT_EQ(0, cache_->GetEntryCount()); } TEST_F(DiskCacheEntryTest, DoomEntry) { + SetDirectMode(); InitCache(); DoomNormalEntry(); } @@ -809,6 +819,7 @@ void DiskCacheEntryTest::DoomedEntry() { ASSERT_EQ(net::OK, CreateEntry(key, &entry)); entry->Doom(); + FlushQueueForTest(); EXPECT_EQ(0, cache_->GetEntryCount()); Time initial = Time::Now(); PlatformThread::Sleep(20); @@ -831,6 +842,7 @@ void DiskCacheEntryTest::DoomedEntry() { } TEST_F(DiskCacheEntryTest, DoomedEntry) { + SetDirectMode(); InitCache(); DoomedEntry(); } @@ -1263,6 +1275,8 @@ void DiskCacheEntryTest::DoomSparseEntry() { } TEST_F(DiskCacheEntryTest, DoomSparseEntry) { + SetDirectMode(); + UseCurrentThread(); InitCache(); DoomSparseEntry(); } @@ -1421,6 +1435,7 @@ TEST_F(DiskCacheEntryTest, CleanupSparseEntry) { } TEST_F(DiskCacheEntryTest, CancelSparseIO) { + UseCurrentThread(); InitCache(); std::string key("the first key"); disk_cache::Entry* entry; @@ -1430,25 +1445,20 @@ TEST_F(DiskCacheEntryTest, CancelSparseIO) { scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); CacheTestFillBuffer(buf->data(), kSize, false); + // This will open and write two "real" entries. TestCompletionCallback cb1, cb2, cb3, cb4, cb5; + int rv = entry->WriteSparseData(1024 * 1024 - 4096, buf, kSize, &cb1); + EXPECT_EQ(net::ERR_IO_PENDING, rv); + int64 offset = 0; - int tries = 0; - const int maxtries = 100; // Avoid hang on infinitely fast disks. - for (int ret = 0; ret != net::ERR_IO_PENDING; offset += kSize * 4) { - ret = entry->WriteSparseData(offset, buf, kSize, &cb1); - if (++tries > maxtries) { - LOG(ERROR) << "Data writes never come back PENDING; skipping test"; - entry->Close(); - return; - } + rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5); + rv = cb5.GetResult(rv); + if (!cb1.have_result()) { + // We may or may not have finished writing to the entry. If we have not, + // we cannot start another operation at this time. + EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED, rv); } - // Cannot use the entry at this point. - offset = 0; - int rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5); - EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED, cb5.GetResult(rv)); - EXPECT_EQ(net::OK, entry->ReadyForSparseIO(&cb2)); - // We cancel the pending operation, and register multiple notifications. entry->CancelSparseIO(); EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(&cb2)); @@ -1456,22 +1466,22 @@ TEST_F(DiskCacheEntryTest, CancelSparseIO) { entry->CancelSparseIO(); // Should be a no op at this point. EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(&cb4)); - offset = 0; - rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5); - EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED, cb5.GetResult(rv)); - EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED, - entry->ReadSparseData(offset, buf, kSize, NULL)); - EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED, - entry->WriteSparseData(offset, buf, kSize, NULL)); - - // Now see if we receive all notifications. - EXPECT_EQ(kSize, cb1.GetResult(net::ERR_IO_PENDING)); - EXPECT_EQ(net::OK, cb2.GetResult(net::ERR_IO_PENDING)); - EXPECT_EQ(net::OK, cb3.GetResult(net::ERR_IO_PENDING)); - EXPECT_EQ(net::OK, cb4.GetResult(net::ERR_IO_PENDING)); + if (!cb1.have_result()) { + EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED, + entry->ReadSparseData(offset, buf, kSize, NULL)); + EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED, + entry->WriteSparseData(offset, buf, kSize, NULL)); + } + + // Now see if we receive all notifications. Note that we should not be able + // to write everything (unless the timing of the system is really weird). + rv = cb1.WaitForResult(); + EXPECT_TRUE(rv == 4096 || rv == kSize); + EXPECT_EQ(net::OK, cb2.WaitForResult()); + EXPECT_EQ(net::OK, cb3.WaitForResult()); + EXPECT_EQ(net::OK, cb4.WaitForResult()); rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5); - EXPECT_EQ(kSize, cb5.GetResult(rv)); - EXPECT_EQ(net::OK, entry->ReadyForSparseIO(&cb2)); + EXPECT_EQ(0, cb5.GetResult(rv)); entry->Close(); } |