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

Unified Diff: net/disk_cache/entry_unittest.cc

Issue 2874833005: SimpleCache: read small files all at once. (Closed)
Patch Set: Add some metrics and an experiment knob. Not really happy with coverage, though. Created 3 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
Index: net/disk_cache/entry_unittest.cc
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index 55f9cf98f265e219a5a0fc5e6250e370ce2f7013..48e5046e54b79ff835cbfe4912addb39de60fd1e 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -74,7 +74,7 @@ class DiskCacheEntryTest : public DiskCacheTestWithCache {
void UpdateSparseEntry();
void DoomSparseEntry();
void PartialSparseEntry();
- bool SimpleCacheMakeBadChecksumEntry(const std::string& key, int* data_size);
+ bool SimpleCacheMakeBadChecksumEntry(const std::string& key, int data_size);
bool SimpleCacheThirdStreamFileExists(const char* key);
void SyncDoomEntry(const char* key);
};
@@ -2631,7 +2631,7 @@ TEST_F(DiskCacheEntryTest, SimpleCacheDoomedEntry) {
// Creates an entry with corrupted last byte in stream 0.
// Requires SimpleCacheMode.
bool DiskCacheEntryTest::SimpleCacheMakeBadChecksumEntry(const std::string& key,
- int* data_size) {
+ int data_size) {
disk_cache::Entry* entry = NULL;
if (CreateEntry(key, &entry) != net::OK || !entry) {
@@ -2639,12 +2639,10 @@ bool DiskCacheEntryTest::SimpleCacheMakeBadChecksumEntry(const std::string& key,
return false;
}
- const char data[] = "this is very good data";
- const int kDataSize = arraysize(data);
- scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kDataSize));
- base::strlcpy(buffer->data(), data, kDataSize);
+ scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(data_size));
+ memset(buffer->data(), 'A', data_size);
- EXPECT_EQ(kDataSize, WriteData(entry, 1, 0, buffer.get(), kDataSize, false));
+ EXPECT_EQ(data_size, WriteData(entry, 1, 0, buffer.get(), data_size, false));
entry->Close();
entry = NULL;
@@ -2657,33 +2655,47 @@ bool DiskCacheEntryTest::SimpleCacheMakeBadChecksumEntry(const std::string& key,
return false;
int64_t file_offset =
- sizeof(disk_cache::SimpleFileHeader) + key.size() + kDataSize - 2;
+ sizeof(disk_cache::SimpleFileHeader) + key.size() + data_size - 2;
EXPECT_EQ(1, entry_file0.Write(file_offset, "X", 1));
- *data_size = kDataSize;
return true;
}
// Tests that the simple cache can detect entries that have bad data.
+TEST_F(DiskCacheEntryTest, SimpleCacheBadChecksumSmall) {
+ base::HistogramTester histogram_tester;
+ SetSimpleCacheMode();
+ InitCache();
+
+ const char key[] = "the first key";
+ ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, 10));
+
+ disk_cache::Entry* entry = NULL;
+
+ // Open the entry. Since we made a small entry, we will detect the CRC
+ // problem at open.
+ EXPECT_THAT(OpenEntry(key, &entry), IsError(net::ERR_FAILED));
+}
+
TEST_F(DiskCacheEntryTest, SimpleCacheBadChecksum) {
base::HistogramTester histogram_tester;
SetSimpleCacheMode();
InitCache();
const char key[] = "the first key";
- int size_unused;
- ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, &size_unused));
+ const int kLargeSize = 50000;
+ ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, kLargeSize));
disk_cache::Entry* entry = NULL;
- // Open the entry.
+ // Open the entry. Can't spot the checksum that quickly with it so
+ // huge.
ASSERT_THAT(OpenEntry(key, &entry), IsOk());
ScopedEntryPtr entry_closer(entry);
- const int kReadBufferSize = 200;
- EXPECT_GE(kReadBufferSize, entry->GetDataSize(1));
- scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kReadBufferSize));
+ EXPECT_GE(kLargeSize, entry->GetDataSize(1));
+ scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kLargeSize));
EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH,
- ReadData(entry, 1, 0, read_buffer.get(), kReadBufferSize));
+ ReadData(entry, 1, 0, read_buffer.get(), kLargeSize));
histogram_tester.ExpectUniqueSample(
"SimpleCache.Http.ReadResult",
disk_cache::READ_RESULT_SYNC_CHECKSUM_FAILURE, 1);
@@ -2696,8 +2708,8 @@ TEST_F(DiskCacheEntryTest, SimpleCacheErrorThenDoom) {
InitCache();
const char key[] = "the first key";
- int size_unused;
- ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, &size_unused));
+ const int kLargeSize = 50000;
+ ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, kLargeSize));
disk_cache::Entry* entry = NULL;
@@ -2705,11 +2717,10 @@ TEST_F(DiskCacheEntryTest, SimpleCacheErrorThenDoom) {
ASSERT_THAT(OpenEntry(key, &entry), IsOk());
ScopedEntryPtr entry_closer(entry);
- const int kReadBufferSize = 200;
- EXPECT_GE(kReadBufferSize, entry->GetDataSize(1));
- scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kReadBufferSize));
+ EXPECT_GE(kLargeSize, entry->GetDataSize(1));
+ scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kLargeSize));
EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH,
- ReadData(entry, 1, 0, read_buffer.get(), kReadBufferSize));
+ ReadData(entry, 1, 0, read_buffer.get(), kLargeSize));
histogram_tester.ExpectUniqueSample(
"SimpleCache.Http.ReadResult",
disk_cache::READ_RESULT_SYNC_CHECKSUM_FAILURE, 1);
@@ -3445,7 +3456,7 @@ TEST_F(DiskCacheEntryTest, SimpleCacheInFlightTruncate) {
const char key[] = "the first key";
- const int kBufferSize = 1024;
+ const int kBufferSize = 50000; // to avoid quick read
scoped_refptr<net::IOBuffer> write_buffer(new net::IOBuffer(kBufferSize));
CacheTestFillBuffer(write_buffer->data(), kBufferSize, false);
@@ -3576,8 +3587,8 @@ TEST_F(DiskCacheEntryTest, SimpleCacheMultipleReadersCheckCRC2) {
InitCache();
const char key[] = "key";
- int size;
- ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, &size));
+ int size = 50000;
+ ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, size));
scoped_refptr<net::IOBuffer> read_buffer1(new net::IOBuffer(size));
scoped_refptr<net::IOBuffer> read_buffer2(new net::IOBuffer(size));

Powered by Google App Engine
This is Rietveld 408576698