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

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

Issue 2791493003: Fix incorrect computation of LastModified in SimpleCache, (Closed)
Patch Set: Deflake on Windows, by: 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 3980 matching lines...) Expand 10 before | Expand all | Expand 10 after
3991 // because that would advance the cache directory mtime and invalidate the 3991 // because that would advance the cache directory mtime and invalidate the
3992 // index. 3992 // index.
3993 entry2->Doom(); 3993 entry2->Doom();
3994 entry2->Close(); 3994 entry2->Close();
3995 3995
3996 DisableFirstCleanup(); 3996 DisableFirstCleanup();
3997 InitCache(); 3997 InitCache();
3998 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, 3998 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED,
3999 simple_cache_impl_->index()->init_method()); 3999 simple_cache_impl_->index()->init_method());
4000 } 4000 }
4001
4002 TEST_F(DiskCacheBackendTest, SimpleLastModified) {
jkarlin 2017/04/21 13:48:33 Please add a comment describing what this test is
Maks Orlovich 2017/04/21 15:12:52 Done.
4003 SetSimpleCacheMode();
4004 InitCache();
4005 std::string key1 = GenerateKey(true);
4006 std::string key2 = GenerateKey(true);
4007
4008 disk_cache::Entry* entry1;
4009 ASSERT_THAT(CreateEntry(key1, &entry1), IsOk());
4010
4011 // Make the Create complete --- SimpleCache can handle it optimistically,
4012 // and if we let it go fully async then trying to flush the Close might just
4013 // flush the Create.
4014 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
4015 base::RunLoop().RunUntilIdle();
4016
4017 entry1->Close();
4018
4019 // Make the ::Close actually complete, since it is asynchronous.
4020 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
4021 base::RunLoop().RunUntilIdle();
4022
4023 Time entry1_timestamp = Time::NowFromSystemTime();
4024
4025 // Don't want AddDelay since it sleep 1s(!) for SimpleCache, and we don't
4026 // care about reduced precision in index here.
4027 while (base::Time::Now() <=
jkarlin 2017/04/21 13:48:33 Also use NowFromSystemTime here?
Maks Orlovich 2017/04/21 15:12:52 Done.
4028 (entry1_timestamp + base::TimeDelta::FromMilliseconds(10))) {
4029 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
4030 }
4031
4032 disk_cache::Entry* entry2;
4033 ASSERT_THAT(CreateEntry(key2, &entry2), IsOk());
4034 entry2->Close();
4035 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
4036 base::RunLoop().RunUntilIdle();
4037
4038 disk_cache::Entry* reopen_entry1;
4039 ASSERT_THAT(OpenEntry(key1, &reopen_entry1), IsOk());
4040
4041 // This shouldn't pick up entry2's write time incorrectly.
4042 EXPECT_LE(reopen_entry1->GetLastModified(), entry1_timestamp);
4043 reopen_entry1->Close();
4044 }
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