diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 22:15:27 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 22:15:27 +0000 |
commit | 9ee9cd8145136bfa422c1213eaeecb4882581698 (patch) | |
tree | ae38220e2f4416ef0af1faa01653d44b05214e7b /net/disk_cache/entry_unittest.cc | |
parent | 60a50ad4551779947cf53f80d33d3da27e51e04b (diff) | |
download | chromium_src-9ee9cd8145136bfa422c1213eaeecb4882581698.zip chromium_src-9ee9cd8145136bfa422c1213eaeecb4882581698.tar.gz chromium_src-9ee9cd8145136bfa422c1213eaeecb4882581698.tar.bz2 |
Disk cache: Remove the queue for backend operations and
change the queue of entry operations so that the operation
that is posted is kept on the list.
BUG=54338
TEST=net_unittests
Review URL: http://codereview.chromium.org/3744007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65118 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/entry_unittest.cc')
-rw-r--r-- | net/disk_cache/entry_unittest.cc | 79 |
1 files changed, 69 insertions, 10 deletions
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc index 84568e3..bea940c 100644 --- a/net/disk_cache/entry_unittest.cc +++ b/net/disk_cache/entry_unittest.cc @@ -475,6 +475,75 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyExternalAsyncIO) { ExternalAsyncIO(); } +TEST_F(DiskCacheEntryTest, RequestThrottling) { + SetDirectMode(); + InitCache(); + disk_cache::Entry* entry = NULL; + ASSERT_EQ(net::OK, CreateEntry("the first key", &entry)); + ASSERT_TRUE(NULL != entry); + + // Let's verify that each IO goes to the right callback object. + CallbackTest cb(true); + + g_cache_tests_error = false; + g_cache_tests_received = 0; + + MessageLoopHelper helper; + + const int kSize = 200; + scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); + CacheTestFillBuffer(buffer->data(), kSize, false); + + int expected = 0; + // Start with no throttling. + for (; expected < 10; expected++) { + int ret = entry->WriteData(0, 0, buffer, kSize, &cb, false); + EXPECT_EQ(net::ERR_IO_PENDING, ret); + } + EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); + + // And now with full throttling. + cache_impl_->ThrottleRequestsForTest(true); + for (; expected < 20; expected++) { + int ret = entry->WriteData(0, 0, buffer, kSize, &cb, false); + EXPECT_EQ(net::ERR_IO_PENDING, ret); + } + EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); + + for (; expected < 30; expected++) { + int ret = entry->WriteData(0, 0, buffer, kSize, &cb, false); + EXPECT_EQ(net::ERR_IO_PENDING, ret); + } + // We have 9 queued requests, lets dispatch them all at once. + cache_impl_->ThrottleRequestsForTest(false); + EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); + + cache_impl_->ThrottleRequestsForTest(true); + for (; expected < 40; expected++) { + int ret = entry->WriteData(0, 0, buffer, kSize, &cb, false); + EXPECT_EQ(net::ERR_IO_PENDING, ret); + } + + // We can close the entry and keep receiving notifications. + entry->Close(); + EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); + + ASSERT_EQ(net::OK, OpenEntry("the first key", &entry)); + for (; expected < 50; expected++) { + int ret = entry->WriteData(0, 0, buffer, kSize, &cb, false); + EXPECT_EQ(net::ERR_IO_PENDING, ret); + } + + // ... and even close the cache. + entry->Close(); + delete cache_impl_; + cache_ = cache_impl_ = NULL; + EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); + + EXPECT_FALSE(g_cache_tests_error); + EXPECT_EQ(expected, g_cache_tests_received); +} + void DiskCacheEntryTest::StreamAccess() { disk_cache::Entry* entry = NULL; ASSERT_EQ(net::OK, CreateEntry("the first key", &entry)); @@ -755,11 +824,6 @@ void DiskCacheEntryTest::TruncateData() { TEST_F(DiskCacheEntryTest, TruncateData) { InitCache(); TruncateData(); - - // We generate asynchronous IO that is not really tracked until completion - // so we just wait here before running the next test. - MessageLoopHelper helper; - helper.WaitUntilCacheIoFinished(1); } TEST_F(DiskCacheEntryTest, TruncateDataNoBuffer) { @@ -767,11 +831,6 @@ TEST_F(DiskCacheEntryTest, TruncateDataNoBuffer) { InitCache(); cache_impl_->SetFlags(disk_cache::kNoBuffering); TruncateData(); - - // We generate asynchronous IO that is not really tracked until completion - // so we just wait here before running the next test. - MessageLoopHelper helper; - helper.WaitUntilCacheIoFinished(1); } TEST_F(DiskCacheEntryTest, MemoryOnlyTruncateData) { |