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

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

Issue 59143006: Work around a flake in the Mac OS watcher test on the bots. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 | « pkg/watcher/test/no_subscription/shared.dart ('k') | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 watcher.test.utils; 5 library watcher.test.utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:io'; 9 import 'dart:io';
10 10
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } finally { 169 } finally {
170 _unorderedEventFuture = oldFuture; 170 _unorderedEventFuture = oldFuture;
171 } 171 }
172 } 172 }
173 173
174 /// Expects that the next set of event will be a change of [type] on [path]. 174 /// Expects that the next set of event will be a change of [type] on [path].
175 /// 175 ///
176 /// Multiple calls to [expectEvent] require that the events are received in that 176 /// Multiple calls to [expectEvent] require that the events are received in that
177 /// order unless they're called in an [inAnyOrder] block. 177 /// order unless they're called in an [inAnyOrder] block.
178 void expectEvent(ChangeType type, String path) { 178 void expectEvent(ChangeType type, String path) {
179 var matcher = predicate((e) {
180 return e is WatchEvent && e.type == type &&
181 e.path == p.join(_sandboxDir, p.normalize(path));
182 }, "is $type $path");
183
184 if (_unorderedEventFuture != null) { 179 if (_unorderedEventFuture != null) {
185 // Assign this to a local variable since it will be un-assigned by the time 180 // Assign this to a local variable since it will be un-assigned by the time
186 // the scheduled callback runs. 181 // the scheduled callback runs.
187 var future = _unorderedEventFuture; 182 var future = _unorderedEventFuture;
188 183
189 expect( 184 expect(
190 schedule(() => future, "should fire $type event on $path"), 185 schedule(() => future, "should fire $type event on $path"),
191 completion(contains(matcher))); 186 completion(contains(isWatchEvent(type, path))));
192 } else { 187 } else {
193 var future = currentSchedule.wrapFuture( 188 var future = currentSchedule.wrapFuture(
194 _watcherEvents.elementAt(_nextEvent), 189 _watcherEvents.elementAt(_nextEvent),
195 "waiting for $type event on $path"); 190 "waiting for $type event on $path");
196 191
197 expect( 192 expect(
198 schedule(() => future, "should fire $type event on $path"), 193 schedule(() => future, "should fire $type event on $path"),
199 completion(matcher)); 194 completion(isWatchEvent(type, path)));
200 } 195 }
201 _nextEvent++; 196 _nextEvent++;
202 } 197 }
203 198
199 /// Returns a matcher that matches a [WatchEvent] with the given [type] and
200 /// [path].
201 Match isWatchEvent(ChangeType type, String path) {
202 return predicate((e) {
203 return e is WatchEvent && e.type == type &&
204 e.path == p.join(_sandboxDir, p.normalize(path));
205 }, "is $type $path");
206 }
207
204 void expectAddEvent(String path) => expectEvent(ChangeType.ADD, path); 208 void expectAddEvent(String path) => expectEvent(ChangeType.ADD, path);
205 void expectModifyEvent(String path) => expectEvent(ChangeType.MODIFY, path); 209 void expectModifyEvent(String path) => expectEvent(ChangeType.MODIFY, path);
206 void expectRemoveEvent(String path) => expectEvent(ChangeType.REMOVE, path); 210 void expectRemoveEvent(String path) => expectEvent(ChangeType.REMOVE, path);
207 211
208 /// Schedules writing a file in the sandbox at [path] with [contents]. 212 /// Schedules writing a file in the sandbox at [path] with [contents].
209 /// 213 ///
210 /// If [contents] is omitted, creates an empty file. If [updatedModified] is 214 /// If [contents] is omitted, creates an empty file. If [updatedModified] is
211 /// `false`, the mock file modification time is not changed. 215 /// `false`, the mock file modification time is not changed.
212 void writeFile(String path, {String contents, bool updateModified}) { 216 void writeFile(String path, {String contents, bool updateModified}) {
213 if (contents == null) contents = ""; 217 if (contents == null) contents = "";
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 void withPermutations(callback(int i, int j, int k), {int limit}) { 291 void withPermutations(callback(int i, int j, int k), {int limit}) {
288 if (limit == null) limit = 3; 292 if (limit == null) limit = 3;
289 for (var i = 0; i < limit; i++) { 293 for (var i = 0; i < limit; i++) {
290 for (var j = 0; j < limit; j++) { 294 for (var j = 0; j < limit; j++) {
291 for (var k = 0; k < limit; k++) { 295 for (var k = 0; k < limit; k++) {
292 callback(i, j, k); 296 callback(i, j, k);
293 } 297 }
294 } 298 }
295 } 299 }
296 } 300 }
OLDNEW
« no previous file with comments | « pkg/watcher/test/no_subscription/shared.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698