diff options
author | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-01 07:36:58 +0000 |
---|---|---|
committer | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-01 07:36:58 +0000 |
commit | 1f332d828675b4a711e8a1e8c56c31966fb51ea8 (patch) | |
tree | 2ebb44129e0d36bb7d2ed6691f65ff34e0b46561 /chrome | |
parent | a9ce3a07feb5a0793fd6279c384b9f822788c317 (diff) | |
download | chromium_src-1f332d828675b4a711e8a1e8c56c31966fb51ea8.zip chromium_src-1f332d828675b4a711e8a1e8c56c31966fb51ea8.tar.gz chromium_src-1f332d828675b4a711e8a1e8c56c31966fb51ea8.tar.bz2 |
Trying to fix flaky error in CopyTreeWorkItemTest.NewNameAndCopyTest
BUG=9086
Review URL: http://codereview.chromium.org/56145
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12944 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/installer/util/copy_tree_work_item_unittest.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/chrome/installer/util/copy_tree_work_item_unittest.cc b/chrome/installer/util/copy_tree_work_item_unittest.cc index b9a2dac3..8b33e44 100644 --- a/chrome/installer/util/copy_tree_work_item_unittest.cc +++ b/chrome/installer/util/copy_tree_work_item_unittest.cc @@ -11,6 +11,7 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" +#include "base/platform_thread.h" #include "base/process_util.h" #include "base/scoped_ptr.h" #include "base/string_util.h" @@ -61,6 +62,19 @@ namespace { file.close(); } + bool IsFileInUse(std::wstring path) { + if (!file_util::PathExists(path)) + return false; + + HANDLE handle = ::CreateFile(path.c_str(), FILE_ALL_ACCESS, + NULL, NULL, OPEN_EXISTING, NULL, NULL); + if (handle == INVALID_HANDLE_VALUE) + return true; + + CloseHandle(handle); + return false; + } + // Simple function to read text from a file. std::wstring ReadTextFile(const std::wstring& filename) { WCHAR contents[64]; @@ -446,6 +460,10 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) { work_item.reset(WorkItem::CreateCopyTreeWorkItem( file_name_from, file_name_to, temp_dir_, WorkItem::NEW_NAME_IF_IN_USE, alternate_to)); + if (IsFileInUse(file_name_to)) + PlatformThread::Sleep(2000); + // If file is still in use, the rest of the test will fail. + ASSERT_FALSE(IsFileInUse(file_name_to)); EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(file_util::PathExists(file_name_from)); |