Commit 67e2ec66 authored by gavinp's avatar gavinp Committed by Commit bot

Deflake SimpleIndexFileTest.WriteThenLoadIndex.

This test was using the wrong mtime as its reference for freshness,
and the index file directory was being created in the wrong order on
creation, which tended to make the first load of an index appear
stale, which was particularly pernicious for a test.

R=jkarlin@chromium.org
BUG=255775

Review URL: https://codereview.chromium.org/705433002

Cr-Commit-Position: refs/heads/master@{#302621}
parent c17c4cf2
...@@ -199,6 +199,15 @@ void SimpleIndexFile::SyncWriteToDisk(net::CacheType cache_type, ...@@ -199,6 +199,15 @@ void SimpleIndexFile::SyncWriteToDisk(net::CacheType cache_type,
scoped_ptr<Pickle> pickle, scoped_ptr<Pickle> pickle,
const base::TimeTicks& start_time, const base::TimeTicks& start_time,
bool app_on_background) { bool app_on_background) {
DCHECK_EQ(index_filename.DirName().value(),
temp_index_filename.DirName().value());
base::FilePath index_file_directory = temp_index_filename.DirName();
if (!base::DirectoryExists(index_file_directory) &&
!base::CreateDirectory(index_file_directory)) {
LOG(ERROR) << "Could not create a directory to hold the index file";
return;
}
// There is a chance that the index containing all the necessary data about // There is a chance that the index containing all the necessary data about
// newly created entries will appear to be stale. This can happen if on-disk // newly created entries will appear to be stale. This can happen if on-disk
// part of a Create operation does not fit into the time budget for the index // part of a Create operation does not fit into the time budget for the index
...@@ -211,14 +220,8 @@ void SimpleIndexFile::SyncWriteToDisk(net::CacheType cache_type, ...@@ -211,14 +220,8 @@ void SimpleIndexFile::SyncWriteToDisk(net::CacheType cache_type,
} }
SerializeFinalData(cache_dir_mtime, pickle.get()); SerializeFinalData(cache_dir_mtime, pickle.get());
if (!WritePickleFile(pickle.get(), temp_index_filename)) { if (!WritePickleFile(pickle.get(), temp_index_filename)) {
if (!base::CreateDirectory(temp_index_filename.DirName())) { LOG(ERROR) << "Failed to write the temporary index file";
LOG(ERROR) << "Could not create a directory to hold the index file"; return;
return;
}
if (!WritePickleFile(pickle.get(), temp_index_filename)) {
LOG(ERROR) << "Failed to write the temporary index file";
return;
}
} }
// Atomically rename the temporary index file to become the real one. // Atomically rename the temporary index file to become the real one.
......
...@@ -188,8 +188,7 @@ TEST_F(SimpleIndexFileTest, LegacyIsIndexFileStale) { ...@@ -188,8 +188,7 @@ TEST_F(SimpleIndexFileTest, LegacyIsIndexFileStale) {
WrappedSimpleIndexFile::LegacyIsIndexFileStale(cache_mtime, index_path)); WrappedSimpleIndexFile::LegacyIsIndexFileStale(cache_mtime, index_path));
} }
// This test is flaky, see http://crbug.com/255775. TEST_F(SimpleIndexFileTest, WriteThenLoadIndex) {
TEST_F(SimpleIndexFileTest, DISABLED_WriteThenLoadIndex) {
base::ScopedTempDir cache_dir; base::ScopedTempDir cache_dir;
ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
...@@ -214,8 +213,7 @@ TEST_F(SimpleIndexFileTest, DISABLED_WriteThenLoadIndex) { ...@@ -214,8 +213,7 @@ TEST_F(SimpleIndexFileTest, DISABLED_WriteThenLoadIndex) {
WrappedSimpleIndexFile simple_index_file(cache_dir.path()); WrappedSimpleIndexFile simple_index_file(cache_dir.path());
base::Time fake_cache_mtime; base::Time fake_cache_mtime;
ASSERT_TRUE(simple_util::GetMTime(simple_index_file.GetIndexFilePath(), ASSERT_TRUE(simple_util::GetMTime(cache_dir.path(), &fake_cache_mtime));
&fake_cache_mtime));
SimpleIndexLoadResult load_index_result; SimpleIndexLoadResult load_index_result;
simple_index_file.LoadIndexEntries(fake_cache_mtime, simple_index_file.LoadIndexEntries(fake_cache_mtime,
GetCallback(), GetCallback(),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment