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

Side by Side Diff: pkg/http/test/utils.dart

Issue 12540010: Work around issue 9252 in scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also fix pkg/http. Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/scheduled_test/test/descriptor_test.dart » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test_utils; 5 library test_utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:json' as json; 9 import 'dart:json' as json;
10 import 'dart:uri'; 10 import 'dart:uri';
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (lines[j].length > 8) { 131 if (lines[j].length > 8) {
132 lines[j] = lines[j].substring(8, lines[j].length); 132 lines[j] = lines[j].substring(8, lines[j].length);
133 } else { 133 } else {
134 lines[j] = ''; 134 lines[j] = '';
135 } 135 }
136 } 136 }
137 137
138 return lines.join('\n'); 138 return lines.join('\n');
139 } 139 }
140 140
141 // TODO(nweiz): Remove this when issue 9252 is fixed.
142 /// Asynchronously recursively deletes [dir]. Returns a [Future] that completes
143 /// when the deletion is done.
144 Future deleteDir(String dir) =>
145 _attemptRetryable(() => new Directory(dir).delete(recursive: true));
146
147 /// On Windows, we sometimes get failures where the directory is still in use
148 /// when we try to do something with it. This is usually because the OS hasn't
149 /// noticed yet that a process using that directory has closed. To be a bit
150 /// more resilient, we wait and retry a few times.
151 ///
152 /// Takes a [callback] which returns a future for the operation being attempted.
153 /// If that future completes with an error, it will slepp and then [callback]
154 /// will be invoked again to retry the operation. It will try a few times before
155 /// giving up.
156 Future _attemptRetryable(Future callback()) {
157 // Only do lame retry logic on Windows.
158 if (Platform.operatingSystem != 'windows') return callback();
159
160 var attempts = 0;
161 makeAttempt(_) {
162 attempts++;
163 return callback().catchError((e) {
164 if (attempts >= 10) {
165 throw 'Could not complete operation. Gave up after $attempts attempts.';
166 }
167
168 return new Future.delayed(new Duration(milliseconds: 500))
169 .then(makeAttempt);
170 });
171 }
172
173 return makeAttempt(null);
174 }
175
141 /// A matcher that matches JSON that parses to a value that matches the inner 176 /// A matcher that matches JSON that parses to a value that matches the inner
142 /// matcher. 177 /// matcher.
143 Matcher parse(matcher) => new _Parse(matcher); 178 Matcher parse(matcher) => new _Parse(matcher);
144 179
145 class _Parse extends BaseMatcher { 180 class _Parse extends BaseMatcher {
146 final Matcher _matcher; 181 final Matcher _matcher;
147 182
148 _Parse(this._matcher); 183 _Parse(this._matcher);
149 184
150 bool matches(item, MatchState matchState) { 185 bool matches(item, MatchState matchState) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 const isSocketIOException = const _SocketIOException(); 233 const isSocketIOException = const _SocketIOException();
199 234
200 /// A matcher for functions that throw SocketIOException. 235 /// A matcher for functions that throw SocketIOException.
201 const Matcher throwsSocketIOException = 236 const Matcher throwsSocketIOException =
202 const Throws(isSocketIOException); 237 const Throws(isSocketIOException);
203 238
204 class _SocketIOException extends TypeMatcher { 239 class _SocketIOException extends TypeMatcher {
205 const _SocketIOException() : super("SocketIOException"); 240 const _SocketIOException() : super("SocketIOException");
206 bool matches(item, MatchState matchState) => item is SocketIOException; 241 bool matches(item, MatchState matchState) => item is SocketIOException;
207 } 242 }
OLDNEW
« no previous file with comments | « no previous file | pkg/scheduled_test/test/descriptor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698