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

Unified Diff: chrome/installer/util/copy_tree_work_item_unittest.cc

Issue 56145: Trying to fix flaky error in CopyTreeWorkItemTest.NewNameAndCopyTest (Closed)
Patch Set: Created 11 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/installer/util/copy_tree_work_item_unittest.cc
diff --git a/chrome/installer/util/copy_tree_work_item_unittest.cc b/chrome/installer/util/copy_tree_work_item_unittest.cc
index b9a2dac350c04dfade7ca431e4793db8b7bead33..8b33e4409ab44a075254f22a8316db36720ae9fb 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));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698