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

Unified Diff: net/disk_cache/backend_unittest.cc

Issue 2791493003: Fix incorrect computation of LastModified in SimpleCache, (Closed)
Patch Set: Apply review feedback Created 3 years, 8 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 | « no previous file | net/disk_cache/simple/simple_synchronous_entry.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/backend_unittest.cc
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 8c13955fa26fa421156671cb5f72ff3c2eef39b6..ca0e0ee8754e18804dd8b13695208b6bfa747f90 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -4037,3 +4037,57 @@ TEST_F(DiskCacheBackendTest, SimpleCacheLateDoom) {
EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED,
simple_cache_impl_->index()->init_method());
}
+
+TEST_F(DiskCacheBackendTest, SimpleLastModified) {
+ // Simple cache used to incorrectly set LastModified on entries based on
+ // timestamp of the cache directory, and not the entries' file
+ // (https://crbug.com/714143). So this test arranges for a situation
+ // where this would occur by doing:
+ // 1) Write entry 1
+ // 2) Delay
+ // 3) Write entry 2. This sets directory time stamp to be different from
+ // timestamp of entry 1 (due to the delay)
+ // It then checks whether the entry 1 got the proper timestamp or not.
+
+ SetSimpleCacheMode();
+ InitCache();
+ std::string key1 = GenerateKey(true);
+ std::string key2 = GenerateKey(true);
+
+ disk_cache::Entry* entry1;
+ ASSERT_THAT(CreateEntry(key1, &entry1), IsOk());
+
+ // Make the Create complete --- SimpleCache can handle it optimistically,
+ // and if we let it go fully async then trying to flush the Close might just
+ // flush the Create.
+ disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
+ base::RunLoop().RunUntilIdle();
+
+ entry1->Close();
+
+ // Make the ::Close actually complete, since it is asynchronous.
+ disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
+ base::RunLoop().RunUntilIdle();
+
+ Time entry1_timestamp = Time::NowFromSystemTime();
+
+ // Don't want AddDelay since it sleep 1s(!) for SimpleCache, and we don't
+ // care about reduced precision in index here.
+ while (base::Time::NowFromSystemTime() <=
+ (entry1_timestamp + base::TimeDelta::FromMilliseconds(10))) {
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
+ }
+
+ disk_cache::Entry* entry2;
+ ASSERT_THAT(CreateEntry(key2, &entry2), IsOk());
+ entry2->Close();
+ disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
+ base::RunLoop().RunUntilIdle();
+
+ disk_cache::Entry* reopen_entry1;
+ ASSERT_THAT(OpenEntry(key1, &reopen_entry1), IsOk());
+
+ // This shouldn't pick up entry2's write time incorrectly.
+ EXPECT_LE(reopen_entry1->GetLastModified(), entry1_timestamp);
+ reopen_entry1->Close();
+}
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_synchronous_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698