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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_synchronous_entry.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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 4019 matching lines...) Expand 10 before | Expand all | Expand 10 after
4030 // because that would advance the cache directory mtime and invalidate the 4030 // because that would advance the cache directory mtime and invalidate the
4031 // index. 4031 // index.
4032 entry2->Doom(); 4032 entry2->Doom();
4033 entry2->Close(); 4033 entry2->Close();
4034 4034
4035 DisableFirstCleanup(); 4035 DisableFirstCleanup();
4036 InitCache(); 4036 InitCache();
4037 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, 4037 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED,
4038 simple_cache_impl_->index()->init_method()); 4038 simple_cache_impl_->index()->init_method());
4039 } 4039 }
4040
4041 TEST_F(DiskCacheBackendTest, SimpleLastModified) {
4042 // Simple cache used to incorrectly set LastModified on entries based on
4043 // timestamp of the cache directory, and not the entries' file
4044 // (https://crbug.com/714143). So this test arranges for a situation
4045 // where this would occur by doing:
4046 // 1) Write entry 1
4047 // 2) Delay
4048 // 3) Write entry 2. This sets directory time stamp to be different from
4049 // timestamp of entry 1 (due to the delay)
4050 // It then checks whether the entry 1 got the proper timestamp or not.
4051
4052 SetSimpleCacheMode();
4053 InitCache();
4054 std::string key1 = GenerateKey(true);
4055 std::string key2 = GenerateKey(true);
4056
4057 disk_cache::Entry* entry1;
4058 ASSERT_THAT(CreateEntry(key1, &entry1), IsOk());
4059
4060 // Make the Create complete --- SimpleCache can handle it optimistically,
4061 // and if we let it go fully async then trying to flush the Close might just
4062 // flush the Create.
4063 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
4064 base::RunLoop().RunUntilIdle();
4065
4066 entry1->Close();
4067
4068 // Make the ::Close actually complete, since it is asynchronous.
4069 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
4070 base::RunLoop().RunUntilIdle();
4071
4072 Time entry1_timestamp = Time::NowFromSystemTime();
4073
4074 // Don't want AddDelay since it sleep 1s(!) for SimpleCache, and we don't
4075 // care about reduced precision in index here.
4076 while (base::Time::NowFromSystemTime() <=
4077 (entry1_timestamp + base::TimeDelta::FromMilliseconds(10))) {
4078 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
4079 }
4080
4081 disk_cache::Entry* entry2;
4082 ASSERT_THAT(CreateEntry(key2, &entry2), IsOk());
4083 entry2->Close();
4084 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
4085 base::RunLoop().RunUntilIdle();
4086
4087 disk_cache::Entry* reopen_entry1;
4088 ASSERT_THAT(OpenEntry(key1, &reopen_entry1), IsOk());
4089
4090 // This shouldn't pick up entry2's write time incorrectly.
4091 EXPECT_LE(reopen_entry1->GetLastModified(), entry1_timestamp);
4092 reopen_entry1->Close();
4093 }
OLDNEW
« 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