OLD | NEW |
---|---|
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 2856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2867 EXPECT_EQ(net::ERR_IO_PENDING, | 2867 EXPECT_EQ(net::ERR_IO_PENDING, |
2868 entry2->ReadData(0, 0, buffer1.get(), kSize1, cb.callback())); | 2868 entry2->ReadData(0, 0, buffer1.get(), kSize1, cb.callback())); |
2869 EXPECT_EQ(kSize1, cb.GetResult(net::ERR_IO_PENDING)); | 2869 EXPECT_EQ(kSize1, cb.GetResult(net::ERR_IO_PENDING)); |
2870 | 2870 |
2871 // Check that we are not leaking. | 2871 // Check that we are not leaking. |
2872 EXPECT_TRUE( | 2872 EXPECT_TRUE( |
2873 static_cast<disk_cache::SimpleEntryImpl*>(entry2)->HasOneRef()); | 2873 static_cast<disk_cache::SimpleEntryImpl*>(entry2)->HasOneRef()); |
2874 entry2->Close(); | 2874 entry2->Close(); |
2875 } | 2875 } |
2876 | 2876 |
2877 // This test is flaky because of the race of Create followed by a Doom. | 2877 TEST_F(DiskCacheEntryTest, SimpleCacheOptimistic5) { |
2878 // See test SimpleCacheCreateDoomRace. | |
2879 TEST_F(DiskCacheEntryTest, DISABLED_SimpleCacheOptimistic5) { | |
2880 // Test sequence: | 2878 // Test sequence: |
2881 // Create, Doom, Write, Read, Close. | 2879 // Create, Doom, Write, Read, Close. |
2882 SetSimpleCacheMode(); | 2880 SetSimpleCacheMode(); |
2883 InitCache(); | 2881 InitCache(); |
2884 disk_cache::Entry* null = NULL; | 2882 disk_cache::Entry* null = NULL; |
2885 const char key[] = "the first key"; | 2883 const char key[] = "the first key"; |
2886 | 2884 |
2887 net::TestCompletionCallback cb; | 2885 net::TestCompletionCallback cb; |
2888 const int kSize1 = 10; | 2886 const int kSize1 = 10; |
2889 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); | 2887 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2938 entry->Doom(); | 2936 entry->Doom(); |
2939 entry->Doom(); | 2937 entry->Doom(); |
2940 | 2938 |
2941 // This Read must not be optimistic, since we don't support that yet. | 2939 // This Read must not be optimistic, since we don't support that yet. |
2942 EXPECT_EQ(net::ERR_IO_PENDING, | 2940 EXPECT_EQ(net::ERR_IO_PENDING, |
2943 entry->ReadData(0, 0, buffer1_read.get(), kSize1, cb.callback())); | 2941 entry->ReadData(0, 0, buffer1_read.get(), kSize1, cb.callback())); |
2944 EXPECT_EQ(kSize1, cb.GetResult(net::ERR_IO_PENDING)); | 2942 EXPECT_EQ(kSize1, cb.GetResult(net::ERR_IO_PENDING)); |
2945 EXPECT_EQ(0, memcmp(buffer1->data(), buffer1_read->data(), kSize1)); | 2943 EXPECT_EQ(0, memcmp(buffer1->data(), buffer1_read->data(), kSize1)); |
2946 | 2944 |
2947 entry->Doom(); | 2945 entry->Doom(); |
2948 | |
2949 // Check that we are not leaking. | |
2950 EXPECT_TRUE( | |
2951 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef()); | |
Randy Smith (Not in Mondays)
2013/09/03 18:48:19
Why could/will this have an extra ref?
Philippe
2013/09/04 09:35:23
The doom above is adding an extra reference to the
| |
2952 } | 2946 } |
2953 | 2947 |
2954 // Confirm that IO buffers are not referenced by the Simple Cache after a write | 2948 // Confirm that IO buffers are not referenced by the Simple Cache after a write |
2955 // completes. | 2949 // completes. |
2956 TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticWriteReleases) { | 2950 TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticWriteReleases) { |
2957 SetSimpleCacheMode(); | 2951 SetSimpleCacheMode(); |
2958 InitCache(); | 2952 InitCache(); |
2959 | 2953 |
2960 const char key[] = "the first key"; | 2954 const char key[] = "the first key"; |
2961 disk_cache::Entry* entry = NULL; | 2955 disk_cache::Entry* entry = NULL; |
(...skipping 18 matching lines...) Expand all Loading... | |
2980 | 2974 |
2981 // Finally, we should perform an optimistic write and confirm that all | 2975 // Finally, we should perform an optimistic write and confirm that all |
2982 // references to the IO buffer have been released. | 2976 // references to the IO buffer have been released. |
2983 EXPECT_EQ( | 2977 EXPECT_EQ( |
2984 kWriteSize, | 2978 kWriteSize, |
2985 entry->WriteData( | 2979 entry->WriteData( |
2986 1, 0, buffer1.get(), kWriteSize, net::CompletionCallback(), false)); | 2980 1, 0, buffer1.get(), kWriteSize, net::CompletionCallback(), false)); |
2987 EXPECT_TRUE(buffer1->HasOneRef()); | 2981 EXPECT_TRUE(buffer1->HasOneRef()); |
2988 } | 2982 } |
2989 | 2983 |
2990 TEST_F(DiskCacheEntryTest, DISABLED_SimpleCacheCreateDoomRace) { | 2984 TEST_F(DiskCacheEntryTest, SimpleCacheCreateDoomRace) { |
2991 // Test sequence: | 2985 // Test sequence: |
2992 // Create, Doom, Write, Close, Check files are not on disk anymore. | 2986 // Create, Doom, Write, Close, Check files are not on disk anymore. |
2993 SetSimpleCacheMode(); | 2987 SetSimpleCacheMode(); |
2994 InitCache(); | 2988 InitCache(); |
2995 disk_cache::Entry* null = NULL; | 2989 disk_cache::Entry* null = NULL; |
2996 const char key[] = "the first key"; | 2990 const char key[] = "the first key"; |
2997 | 2991 |
2998 net::TestCompletionCallback cb; | 2992 net::TestCompletionCallback cb; |
2999 const int kSize1 = 10; | 2993 const int kSize1 = 10; |
3000 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); | 2994 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
3001 CacheTestFillBuffer(buffer1->data(), kSize1, false); | 2995 CacheTestFillBuffer(buffer1->data(), kSize1, false); |
3002 disk_cache::Entry* entry = NULL; | 2996 disk_cache::Entry* entry = NULL; |
3003 | 2997 |
3004 ASSERT_EQ(net::OK, | 2998 ASSERT_EQ(net::OK, |
3005 cache_->CreateEntry(key, &entry, net::CompletionCallback())); | 2999 cache_->CreateEntry(key, &entry, net::CompletionCallback())); |
3006 EXPECT_NE(null, entry); | 3000 EXPECT_NE(null, entry); |
3007 | 3001 |
3008 cache_->DoomEntry(key, cb.callback()); | 3002 cache_->DoomEntry(key, cb.callback()); |
3009 EXPECT_EQ(net::OK, cb.GetResult(net::ERR_IO_PENDING)); | 3003 EXPECT_EQ(net::OK, cb.GetResult(net::ERR_IO_PENDING)); |
3010 | 3004 |
3011 // Lets do a Write so we block until all operations are done, so we can check | |
3012 // the HasOneRef() below. This call can't be optimistic and we are checking | |
Philippe
2013/08/28 14:05:52
Why can't this be optimistic? It is optimistic cur
| |
3013 // that here. | |
3014 EXPECT_EQ( | 3005 EXPECT_EQ( |
3015 net::ERR_IO_PENDING, | 3006 kSize1, |
3016 entry->WriteData(0, 0, buffer1.get(), kSize1, cb.callback(), false)); | 3007 entry->WriteData(0, 0, buffer1.get(), kSize1, cb.callback(), false)); |
3017 EXPECT_EQ(kSize1, cb.GetResult(net::ERR_IO_PENDING)); | |
3018 | 3008 |
3019 // Check that we are not leaking. | |
3020 EXPECT_TRUE( | |
3021 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef()); | |
3022 entry->Close(); | 3009 entry->Close(); |
3023 | 3010 |
3024 // Finish running the pending tasks so that we fully complete the close | 3011 // Finish running the pending tasks so that we fully complete the close |
3025 // operation and destroy the entry object. | 3012 // operation and destroy the entry object. |
3026 base::MessageLoop::current()->RunUntilIdle(); | 3013 base::MessageLoop::current()->RunUntilIdle(); |
3027 | 3014 |
3028 for (int i = 0; i < disk_cache::kSimpleEntryFileCount; ++i) { | 3015 for (int i = 0; i < disk_cache::kSimpleEntryFileCount; ++i) { |
3029 base::FilePath entry_file_path = cache_path_.AppendASCII( | 3016 base::FilePath entry_file_path = cache_path_.AppendASCII( |
3030 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, i)); | 3017 disk_cache::simple_util::GetFilenameFromKeyAndIndex(key, i)); |
3031 base::PlatformFileInfo info; | 3018 base::PlatformFileInfo info; |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3396 | 3383 |
3397 // Check that we are not leaking. | 3384 // Check that we are not leaking. |
3398 ASSERT_NE(entry, null); | 3385 ASSERT_NE(entry, null); |
3399 EXPECT_TRUE( | 3386 EXPECT_TRUE( |
3400 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef()); | 3387 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef()); |
3401 entry->Close(); | 3388 entry->Close(); |
3402 entry = NULL; | 3389 entry = NULL; |
3403 } | 3390 } |
3404 | 3391 |
3405 #endif // defined(OS_POSIX) | 3392 #endif // defined(OS_POSIX) |
OLD | NEW |