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

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: 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
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 iters = 25;
Paweł Hajdan Jr. 2012/01/03 08:06:46 nit: No abbreviations, also if this is a constant
67 const base::TimeDelta kTimeout = base::TimeDelta::FromSeconds(10) / iters;
67 68
68 if (!file_util::PathExists(file)) 69 if (!file_util::PathExists(file))
69 return true; 70 return true;
70 71
71 // Sometimes Delete fails, so try a few more times. Divide the timeout 72 // 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 73 // into short chunks, so that if a try succeeds, we won't delay the test
73 // for too long. 74 // for too long.
74 for (int i = 0; i < 25; ++i) { 75 for (int i = 0; i < iters; ++i) {
75 if (file_util::Delete(file, recurse)) 76 if (file_util::Delete(file, recurse))
76 return true; 77 return true;
77 base::PlatformThread::Sleep(kTimeoutMs / 25); 78 base::PlatformThread::Sleep(kTimeout);
78 } 79 }
79 return false; 80 return false;
80 } 81 }
81 82
82 bool EvictFileFromSystemCache(const FilePath& file) { 83 bool EvictFileFromSystemCache(const FilePath& file) {
83 // Request exclusive access to the file and overwrite it with no buffering. 84 // Request exclusive access to the file and overwrite it with no buffering.
84 base::win::ScopedHandle file_handle( 85 base::win::ScopedHandle file_handle(
85 CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, 86 CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL,
86 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL)); 87 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL));
87 if (!file_handle) 88 if (!file_handle)
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 271
271 bool MakeFileUnreadable(const FilePath& path) { 272 bool MakeFileUnreadable(const FilePath& path) {
272 return DenyFilePermission(path, GENERIC_READ); 273 return DenyFilePermission(path, GENERIC_READ);
273 } 274 }
274 275
275 bool MakeFileUnwritable(const FilePath& path) { 276 bool MakeFileUnwritable(const FilePath& path) {
276 return DenyFilePermission(path, GENERIC_WRITE); 277 return DenyFilePermission(path, GENERIC_WRITE);
277 } 278 }
278 279
279 } // namespace file_util 280 } // namespace file_util
OLDNEW
« no previous file with comments | « no previous file | base/test/trace_event_analyzer_unittest.cc » ('j') | base/test/trace_event_analyzer_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698