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

Side by Side Diff: pkg/watcher/test/no_subscription/shared.dart

Issue 46843003: Wrap Directory.watch on linux for the watcher package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review 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
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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:scheduled_test/scheduled_test.dart'; 7 import 'package:scheduled_test/scheduled_test.dart';
8 import 'package:watcher/watcher.dart'; 8 import 'package:watcher/watcher.dart';
9 9
10 import 'utils.dart'; 10 import '../utils.dart';
11 11
12 main() { 12 sharedTests() {
13 initConfig(); 13 test('does not notify for changes when there are no subscribers', () {
14
15 setUp(createSandbox);
16
17 test('does not notify for changes when there were no subscribers', () {
18 // Note that this test doesn't rely as heavily on the test functions in 14 // Note that this test doesn't rely as heavily on the test functions in
19 // utils.dart because it needs to be very explicit about when the event 15 // utils.dart because it needs to be very explicit about when the event
20 // stream is and is not subscribed. 16 // stream is and is not subscribed.
21 var watcher = createWatcher(); 17 var watcher = createWatcher();
22 18
23 // Subscribe to the events. 19 // Subscribe to the events.
24 var completer = new Completer(); 20 var completer = new Completer();
25 var subscription = watcher.events.listen(wrapAsync((event) { 21 var subscription = watcher.events.listen(wrapAsync((event) {
26 expect(event.type, equals(ChangeType.ADD)); 22 expect(event.type, equals(ChangeType.ADD));
27 expect(event.path, endsWith("file.txt")); 23 expect(event.path, endsWith("file.txt"));
(...skipping 16 matching lines...) Expand all
44 // Then start listening again. 40 // Then start listening again.
45 schedule(() { 41 schedule(() {
46 completer = new Completer(); 42 completer = new Completer();
47 subscription = watcher.events.listen(wrapAsync((event) { 43 subscription = watcher.events.listen(wrapAsync((event) {
48 // We should get an event for the third file, not the one added while 44 // We should get an event for the third file, not the one added while
49 // we weren't subscribed. 45 // we weren't subscribed.
50 expect(event.type, equals(ChangeType.ADD)); 46 expect(event.type, equals(ChangeType.ADD));
51 expect(event.path, endsWith("added.txt")); 47 expect(event.path, endsWith("added.txt"));
52 completer.complete(); 48 completer.complete();
53 })); 49 }));
50
51 // Wait until the watcher is ready to dispatch events again.
52 return watcher.ready;
54 }); 53 });
55 54
56 // The watcher will have been cancelled and then resumed in the middle of
57 // its pause between polling loops. That means the second scan to skip
58 // what changed while we were unsubscribed won't happen until after that
59 // delay is done. Wait long enough for that to happen.
60 //
61 // We're doing * 4 here because that seems to give the slower bots enough
62 // time for this to complete.
63 schedule(() => new Future.delayed(watcher.pollingDelay * 4));
64
65 // And add a third file. 55 // And add a third file.
66 writeFile("added.txt"); 56 writeFile("added.txt");
67 57
68 // Wait until we get an event for the third file. 58 // Wait until we get an event for the third file.
69 schedule(() => completer.future); 59 schedule(() => completer.future);
70 60
71 schedule(() { 61 schedule(() {
72 subscription.cancel(); 62 subscription.cancel();
73 }); 63 });
74 }); 64 });
75 } 65 }
OLDNEW
« no previous file with comments | « pkg/watcher/test/no_subscription/polling_test.dart ('k') | pkg/watcher/test/no_subscription_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698