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

Side by Side Diff: base/test/test_file_util_win.cc

Issue 9057001: Update Sleep() calls in base/test to use TimeDelta instead of int. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Make variable names style guide consistent. Created 8 years, 11 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 | base/test/trace_event_analyzer_unittest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/test/test_file_util.h" 5 #include "base/test/test_file_util.h"
6 6
7 #include <aclapi.h> 7 #include <aclapi.h>
8 #include <shlwapi.h> 8 #include <shlwapi.h>
9 #include <windows.h> 9 #include <windows.h>
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 LocalFree(security_descriptor); 56 LocalFree(security_descriptor);
57 LocalFree(new_dacl); 57 LocalFree(new_dacl);
58 58
59 return rc == ERROR_SUCCESS; 59 return rc == ERROR_SUCCESS;
60 } 60 }
61 61
62 } // namespace 62 } // namespace
63 63
64 bool DieFileDie(const FilePath& file, bool recurse) { 64 bool DieFileDie(const FilePath& file, bool recurse) {
65 // It turns out that to not induce flakiness a long timeout is needed. 65 // It turns out that to not induce flakiness a long timeout is needed.
66 const int kTimeoutMs = 10000; 66 const int kIterations = 25;
67 const base::TimeDelta kTimeout = base::TimeDelta::FromSeconds(10) /
68 kIterations;
67 69
68 if (!file_util::PathExists(file)) 70 if (!file_util::PathExists(file))
69 return true; 71 return true;
70 72
71 // Sometimes Delete fails, so try a few more times. Divide the timeout 73 // Sometimes Delete fails, so try a few more times. Divide the timeout
72 // into short chunks, so that if a try succeeds, we won't delay the test 74 // into short chunks, so that if a try succeeds, we won't delay the test
73 // for too long. 75 // for too long.
74 for (int i = 0; i < 25; ++i) { 76 for (int i = 0; i < kIterations; ++i) {
75 if (file_util::Delete(file, recurse)) 77 if (file_util::Delete(file, recurse))
76 return true; 78 return true;
77 base::PlatformThread::Sleep(kTimeoutMs / 25); 79 base::PlatformThread::Sleep(kTimeout);
78 } 80 }
79 return false; 81 return false;
80 } 82 }
81 83
82 bool EvictFileFromSystemCache(const FilePath& file) { 84 bool EvictFileFromSystemCache(const FilePath& file) {
83 // Request exclusive access to the file and overwrite it with no buffering. 85 // Request exclusive access to the file and overwrite it with no buffering.
84 base::win::ScopedHandle file_handle( 86 base::win::ScopedHandle file_handle(
85 CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, 87 CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL,
86 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL)); 88 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL));
87 if (!file_handle) 89 if (!file_handle)
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 272
271 bool MakeFileUnreadable(const FilePath& path) { 273 bool MakeFileUnreadable(const FilePath& path) {
272 return DenyFilePermission(path, GENERIC_READ); 274 return DenyFilePermission(path, GENERIC_READ);
273 } 275 }
274 276
275 bool MakeFileUnwritable(const FilePath& path) { 277 bool MakeFileUnwritable(const FilePath& path) {
276 return DenyFilePermission(path, GENERIC_WRITE); 278 return DenyFilePermission(path, GENERIC_WRITE);
277 } 279 }
278 280
279 } // namespace file_util 281 } // namespace file_util
OLDNEW
« no previous file with comments | « no previous file | base/test/trace_event_analyzer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698