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

Side by Side Diff: net/disk_cache/entry_unittest.cc

Issue 23591048: Fix Simple Cache race on multiple dooms in flight. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remedaite Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/disk_cache/simple/simple_entry_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 3067 matching lines...) Expand 10 before | Expand all | Expand 10 after
3078 net::TestCompletionCallback cb; 3078 net::TestCompletionCallback cb;
3079 EXPECT_EQ(net::OK, 3079 EXPECT_EQ(net::OK,
3080 cb.GetResult(simple_entry1->DoomEntry(cb.callback()))); 3080 cb.GetResult(simple_entry1->DoomEntry(cb.callback())));
3081 3081
3082 disk_cache::Entry* entry3 = NULL; 3082 disk_cache::Entry* entry3 = NULL;
3083 ASSERT_EQ(net::OK, OpenEntry(key, &entry3)); 3083 ASSERT_EQ(net::OK, OpenEntry(key, &entry3));
3084 ScopedEntryPtr entry3_closer(entry3); 3084 ScopedEntryPtr entry3_closer(entry3);
3085 EXPECT_NE(null, entry3); 3085 EXPECT_NE(null, entry3);
3086 } 3086 }
3087 3087
3088 TEST_F(DiskCacheEntryTest, SimpleCacheDoomCreateDoom) {
3089 // Test sequence:
3090 // Create, Doom, Create, Doom.
3091 SetSimpleCacheMode();
3092 InitCache();
3093
3094 disk_cache::Entry* null = NULL;
3095
3096 const char key[] = "the first key";
3097
3098 disk_cache::Entry* entry1 = NULL;
3099 ASSERT_EQ(net::OK, CreateEntry(key, &entry1));
3100 ScopedEntryPtr entry1_closer(entry1);
3101 EXPECT_NE(null, entry1);
3102
3103 entry1->Doom();
3104
3105 disk_cache::Entry* entry2 = NULL;
3106 ASSERT_EQ(net::OK, CreateEntry(key, &entry2));
3107 ScopedEntryPtr entry2_closer(entry2);
3108 EXPECT_NE(null, entry2);
3109
3110 entry2->Doom();
3111
3112 // This test passes if it doesn't crash.
3113 }
3114
3088 // Checks that an optimistic Create would fail later on a racing Open. 3115 // Checks that an optimistic Create would fail later on a racing Open.
3089 TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticCreateFailsOnOpen) { 3116 TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticCreateFailsOnOpen) {
3090 SetSimpleCacheMode(); 3117 SetSimpleCacheMode();
3091 InitCache(); 3118 InitCache();
3092 3119
3093 // Create a corrupt file in place of a future entry. Optimistic create should 3120 // Create a corrupt file in place of a future entry. Optimistic create should
3094 // initially succeed, but realize later that creation failed. 3121 // initially succeed, but realize later that creation failed.
3095 const std::string key = "the key"; 3122 const std::string key = "the key";
3096 net::TestCompletionCallback cb; 3123 net::TestCompletionCallback cb;
3097 disk_cache::Entry* entry = NULL; 3124 disk_cache::Entry* entry = NULL;
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
3449 3476
3450 // Check that we are not leaking. 3477 // Check that we are not leaking.
3451 ASSERT_NE(entry, null); 3478 ASSERT_NE(entry, null);
3452 EXPECT_TRUE( 3479 EXPECT_TRUE(
3453 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef()); 3480 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef());
3454 entry->Close(); 3481 entry->Close();
3455 entry = NULL; 3482 entry = NULL;
3456 } 3483 }
3457 3484
3458 #endif // defined(OS_POSIX) 3485 #endif // defined(OS_POSIX)
OLDNEW
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/disk_cache/simple/simple_entry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698