diff options
author | gavinp <gavinp@chromium.org> | 2014-11-04 09:14:23 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-04 17:14:39 +0000 |
commit | 67e2ec660017eb124889df3400e1c2298c656e6f (patch) | |
tree | d602083ae3d44efe35b9669ee4c48d75e589d03d /net/disk_cache | |
parent | c17c4cf24972a763a82230383fd40bd29620bab3 (diff) | |
download | chromium_src-67e2ec660017eb124889df3400e1c2298c656e6f.zip chromium_src-67e2ec660017eb124889df3400e1c2298c656e6f.tar.gz chromium_src-67e2ec660017eb124889df3400e1c2298c656e6f.tar.bz2 |
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}
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/simple/simple_index_file.cc | 19 | ||||
-rw-r--r-- | net/disk_cache/simple/simple_index_file_unittest.cc | 6 |
2 files changed, 13 insertions, 12 deletions
diff --git a/net/disk_cache/simple/simple_index_file.cc b/net/disk_cache/simple/simple_index_file.cc index 37347c8..ac71330 100644 --- a/net/disk_cache/simple/simple_index_file.cc +++ b/net/disk_cache/simple/simple_index_file.cc @@ -199,6 +199,15 @@ void SimpleIndexFile::SyncWriteToDisk(net::CacheType cache_type, scoped_ptr<Pickle> pickle, const base::TimeTicks& start_time, 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 // 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 @@ -211,14 +220,8 @@ void SimpleIndexFile::SyncWriteToDisk(net::CacheType cache_type, } SerializeFinalData(cache_dir_mtime, pickle.get()); if (!WritePickleFile(pickle.get(), temp_index_filename)) { - if (!base::CreateDirectory(temp_index_filename.DirName())) { - LOG(ERROR) << "Could not create a directory to hold the index file"; - return; - } - if (!WritePickleFile(pickle.get(), temp_index_filename)) { - LOG(ERROR) << "Failed to write the temporary index file"; - return; - } + LOG(ERROR) << "Failed to write the temporary index file"; + return; } // Atomically rename the temporary index file to become the real one. diff --git a/net/disk_cache/simple/simple_index_file_unittest.cc b/net/disk_cache/simple/simple_index_file_unittest.cc index 49eb8fb..77db225 100644 --- a/net/disk_cache/simple/simple_index_file_unittest.cc +++ b/net/disk_cache/simple/simple_index_file_unittest.cc @@ -188,8 +188,7 @@ TEST_F(SimpleIndexFileTest, LegacyIsIndexFileStale) { WrappedSimpleIndexFile::LegacyIsIndexFileStale(cache_mtime, index_path)); } -// This test is flaky, see http://crbug.com/255775. -TEST_F(SimpleIndexFileTest, DISABLED_WriteThenLoadIndex) { +TEST_F(SimpleIndexFileTest, WriteThenLoadIndex) { base::ScopedTempDir cache_dir; ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); @@ -214,8 +213,7 @@ TEST_F(SimpleIndexFileTest, DISABLED_WriteThenLoadIndex) { WrappedSimpleIndexFile simple_index_file(cache_dir.path()); base::Time fake_cache_mtime; - ASSERT_TRUE(simple_util::GetMTime(simple_index_file.GetIndexFilePath(), - &fake_cache_mtime)); + ASSERT_TRUE(simple_util::GetMTime(cache_dir.path(), &fake_cache_mtime)); SimpleIndexLoadResult load_index_result; simple_index_file.LoadIndexEntries(fake_cache_mtime, GetCallback(), |