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

Side by Side Diff: pkg/watcher/test/ready_test.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
« no previous file with comments | « pkg/watcher/test/ready/shared.dart ('k') | pkg/watcher/test/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6
7 import 'package:scheduled_test/scheduled_test.dart';
8
9 import 'utils.dart';
10
11 main() {
12 initConfig();
13
14 setUp(createSandbox);
15
16 test('ready does not complete until after subscription', () {
17 var watcher = createWatcher(waitForReady: false);
18
19 var ready = false;
20 watcher.ready.then((_) {
21 ready = true;
22 });
23
24 // Should not be ready yet.
25 schedule(() {
26 expect(ready, isFalse);
27 });
28
29 // Subscribe to the events.
30 schedule(() {
31 var subscription = watcher.events.listen((event) {});
32
33 currentSchedule.onComplete.schedule(() {
34 subscription.cancel();
35 });
36 });
37
38 // Should eventually be ready.
39 schedule(() => watcher.ready);
40
41 schedule(() {
42 expect(ready, isTrue);
43 });
44 });
45
46 test('ready completes immediately when already ready', () {
47 var watcher = createWatcher(waitForReady: false);
48
49 // Subscribe to the events.
50 schedule(() {
51 var subscription = watcher.events.listen((event) {});
52
53 currentSchedule.onComplete.schedule(() {
54 subscription.cancel();
55 });
56 });
57
58 // Should eventually be ready.
59 schedule(() => watcher.ready);
60
61 // Now ready should be a future that immediately completes.
62 var ready = false;
63 schedule(() {
64 watcher.ready.then((_) {
65 ready = true;
66 });
67 });
68
69 schedule(() {
70 expect(ready, isTrue);
71 });
72 });
73
74 test('ready returns a future that does not complete after unsubscribing', () {
75 var watcher = createWatcher(waitForReady: false);
76
77 // Subscribe to the events.
78 var subscription;
79 schedule(() {
80 subscription = watcher.events.listen((event) {});
81 });
82
83 var ready = false;
84
85 // Wait until ready.
86 schedule(() => watcher.ready);
87
88 // Now unsubscribe.
89 schedule(() {
90 subscription.cancel();
91
92 // Track when it's ready again.
93 ready = false;
94 watcher.ready.then((_) {
95 ready = true;
96 });
97 });
98
99 // Should be back to not ready.
100 schedule(() {
101 expect(ready, isFalse);
102 });
103 });
104 }
OLDNEW
« no previous file with comments | « pkg/watcher/test/ready/shared.dart ('k') | pkg/watcher/test/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698