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

Unified Diff: net/disk_cache/entry_unittest.cc

Issue 3054012: Disk Cache: Replace the backend pointer of the ChildrenDeleter... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 5 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/sparse_control.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/entry_unittest.cc
===================================================================
--- net/disk_cache/entry_unittest.cc (revision 53428)
+++ net/disk_cache/entry_unittest.cc (working copy)
@@ -1287,6 +1287,55 @@
DoomSparseEntry();
}
+// A CompletionCallback that deletes the cache from within the callback. The way
+// a TestCompletionCallback works means that all tasks (even new ones) are
+// executed by the message loop before returning to the caller so the only way
+// to simulate a race is to execute what we want on the callback.
+class SparseTestCompletionCallback : public TestCompletionCallback {
+public:
gavinp 2010/07/27 15:29:44 " public:" http://google-styleguide.googlecode.co
+ explicit SparseTestCompletionCallback(disk_cache::Backend* cache)
+ : cache_(cache) {}
+
+ virtual void RunWithParams(const Tuple1<int>& params) {
+ delete cache_;
+ TestCompletionCallback::RunWithParams(params);
+ }
+private:
gavinp 2010/07/27 15:29:44 " private:" http://google-styleguide.googlecode.c
+ disk_cache::Backend* cache_;
+ DISALLOW_COPY_AND_ASSIGN(SparseTestCompletionCallback);
+};
+
+// Tests that we don't crash when the backend is deleted while we are working
+// deleting the sub-entries of a sparse entry.
+TEST_F(DiskCacheEntryTest, DoomSparseEntry2) {
+ SetDirectMode();
+ UseCurrentThread();
+ InitCache();
+ std::string key("the key");
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+
+ const int kSize = 4 * 1024;
+ scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize);
+ CacheTestFillBuffer(buf->data(), kSize, false);
+
+ int64 offset = 1024;
+ // Write to a bunch of ranges.
+ for (int i = 0; i < 12; i++) {
+ EXPECT_EQ(kSize, entry->WriteSparseData(offset, buf, kSize, NULL));
+ offset *= 4;
+ }
+ EXPECT_EQ(9, cache_->GetEntryCount());
+
+ entry->Close();
+ SparseTestCompletionCallback cb(cache_);
+ int rv = cache_->DoomEntry(key, &cb);
+ EXPECT_EQ(net::ERR_IO_PENDING, rv);
+ EXPECT_EQ(net::OK, cb.WaitForResult());
+
+ cache_ = NULL;
gavinp 2010/07/27 15:29:44 What does this do?
rvargas (doing something else) 2010/07/27 18:26:30 We deleted the cache in the callback, but the test
+}
+
void DiskCacheEntryTest::PartialSparseEntry() {
std::string key("the first key");
disk_cache::Entry* entry;
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/sparse_control.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698