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

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

Issue 129473003: Use stream matchers to unflake the mac OS watcher tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « pkg/watcher/test/directory_watcher/mac_os_test.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
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 'package:scheduled_test/scheduled_test.dart'; 5 import 'package:scheduled_test/scheduled_test.dart';
6 import 'package:watcher/src/utils.dart';
6 7
7 import '../utils.dart'; 8 import '../utils.dart';
8 9
9 sharedTests() { 10 sharedTests() {
10 test('does not notify for files that already exist when started', () { 11 test('does not notify for files that already exist when started', () {
11 // Make some pre-existing files. 12 // Make some pre-existing files.
12 writeFile("a.txt"); 13 writeFile("a.txt");
13 writeFile("b.txt"); 14 writeFile("b.txt");
14 15
15 startWatcher(); 16 startWatcher();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 expectModifyEvent("file.txt"); 52 expectModifyEvent("file.txt");
52 }); 53 });
53 54
54 test('notifies even if the file contents are unchanged', () { 55 test('notifies even if the file contents are unchanged', () {
55 writeFile("a.txt", contents: "same"); 56 writeFile("a.txt", contents: "same");
56 writeFile("b.txt", contents: "before"); 57 writeFile("b.txt", contents: "before");
57 startWatcher(); 58 startWatcher();
58 59
59 writeFile("a.txt", contents: "same"); 60 writeFile("a.txt", contents: "same");
60 writeFile("b.txt", contents: "after"); 61 writeFile("b.txt", contents: "after");
61 inAnyOrder(() { 62 inAnyOrder([
62 expectModifyEvent("a.txt"); 63 isModifyEvent("a.txt"),
63 expectModifyEvent("b.txt"); 64 isModifyEvent("b.txt")
64 }); 65 ]);
65 }); 66 });
66 67
67 test('when the watched directory is deleted, removes all files', () { 68 test('when the watched directory is deleted, removes all files', () {
68 writeFile("dir/a.txt"); 69 writeFile("dir/a.txt");
69 writeFile("dir/b.txt"); 70 writeFile("dir/b.txt");
70 71
71 startWatcher(dir: "dir"); 72 startWatcher(dir: "dir");
72 73
73 deleteDir("dir"); 74 deleteDir("dir");
74 inAnyOrder(() { 75 inAnyOrder([
75 expectRemoveEvent("dir/a.txt"); 76 isRemoveEvent("dir/a.txt"),
76 expectRemoveEvent("dir/b.txt"); 77 isRemoveEvent("dir/b.txt"),
77 }); 78 ]);
78 }); 79 });
79 80
80 group("moves", () { 81 group("moves", () {
81 test('notifies when a file is moved within the watched directory', () { 82 test('notifies when a file is moved within the watched directory', () {
82 writeFile("old.txt"); 83 writeFile("old.txt");
83 startWatcher(); 84 startWatcher();
84 renameFile("old.txt", "new.txt"); 85 renameFile("old.txt", "new.txt");
85 86
86 inAnyOrder(() { 87 inAnyOrder([
87 expectAddEvent("new.txt"); 88 isAddEvent("new.txt"),
88 expectRemoveEvent("old.txt"); 89 isRemoveEvent("old.txt"),
89 }); 90 ]);
90 }); 91 });
91 92
92 test('notifies when a file is moved from outside the watched directory', 93 test('notifies when a file is moved from outside the watched directory',
93 () { 94 () {
94 writeFile("old.txt"); 95 writeFile("old.txt");
95 createDir("dir"); 96 createDir("dir");
96 startWatcher(dir: "dir"); 97 startWatcher(dir: "dir");
97 98
98 renameFile("old.txt", "dir/new.txt"); 99 renameFile("old.txt", "dir/new.txt");
99 expectAddEvent("dir/new.txt"); 100 expectAddEvent("dir/new.txt");
100 }); 101 });
101 102
102 test('notifies when a file is moved outside the watched directory', () { 103 test('notifies when a file is moved outside the watched directory', () {
103 writeFile("dir/old.txt"); 104 writeFile("dir/old.txt");
104 startWatcher(dir: "dir"); 105 startWatcher(dir: "dir");
105 106
106 renameFile("dir/old.txt", "new.txt"); 107 renameFile("dir/old.txt", "new.txt");
107 expectRemoveEvent("dir/old.txt"); 108 expectRemoveEvent("dir/old.txt");
108 }); 109 });
109 }); 110 });
110 111
111 group("clustered changes", () { 112 group("clustered changes", () {
112 test("doesn't notify when a file is created and then immediately removed", 113 test("doesn't notify when a file is created and then immediately removed",
113 () { 114 () {
114 startWatcher(); 115 startWatcher();
115 writeFile("file.txt"); 116 writeFile("file.txt");
116 deleteFile("file.txt"); 117 deleteFile("file.txt");
117 118
118 // [startWatcher] will assert that no events were fired. 119 startClosingEventStream();
120
121 allowEvents(() {
122 expectAddEvent("file.txt");
123 expectRemoveEvent("file.txt");
Bob Nystrom 2014/01/09 00:34:22 Seems like this contradicts the test description.
nweiz 2014/01/09 21:59:20 In theory this could happen with any watcher; they
Bob Nystrom 2014/01/09 22:49:19 Has it actually been seen to happen with the other
nweiz 2014/01/10 01:05:31 No, but it could in theory. I don't want to disall
124 });
119 }); 125 });
120 126
121 test("reports a modification when a file is deleted and then immediately " 127 test("reports a modification when a file is deleted and then immediately "
122 "recreated", () { 128 "recreated", () {
123 writeFile("file.txt"); 129 writeFile("file.txt");
124 startWatcher(); 130 startWatcher();
125 131
126 deleteFile("file.txt"); 132 deleteFile("file.txt");
127 writeFile("file.txt", contents: "re-created"); 133 writeFile("file.txt", contents: "re-created");
128 expectModifyEvent("file.txt"); 134
135 allowEither(() {
136 expectModifyEvent("file.txt");
137 }, () {
138 expectRemoveEvent("file.txt");
139 expectAddEvent("file.txt");
140 });
129 }); 141 });
130 142
131 test("reports a modification when a file is moved and then immediately " 143 test("reports a modification when a file is moved and then immediately "
132 "recreated", () { 144 "recreated", () {
133 writeFile("old.txt"); 145 writeFile("old.txt");
134 startWatcher(); 146 startWatcher();
135 147
136 renameFile("old.txt", "new.txt"); 148 renameFile("old.txt", "new.txt");
137 writeFile("old.txt", contents: "re-created"); 149 writeFile("old.txt", contents: "re-created");
138 inAnyOrder(() { 150
139 expectModifyEvent("old.txt"); 151 allowEither(() {
152 inAnyOrder([
153 isModifyEvent("old.txt"),
154 isAddEvent("new.txt"),
155 ]);
156 }, () {
157 expectRemoveEvent("old.txt");
140 expectAddEvent("new.txt"); 158 expectAddEvent("new.txt");
159 expectAddEvent("old.txt");
Bob Nystrom 2014/01/09 00:34:22 Some docs explaining why/where this behavior can s
nweiz 2014/01/09 21:59:20 Added a comment at the top of the "clustered chang
141 }); 160 });
142 }); 161 });
143 162
144 test("reports a removal when a file is modified and then immediately " 163 test("reports a removal when a file is modified and then immediately "
145 "removed", () { 164 "removed", () {
146 writeFile("file.txt"); 165 writeFile("file.txt");
147 startWatcher(); 166 startWatcher();
148 167
149 writeFile("file.txt", contents: "modified"); 168 writeFile("file.txt", contents: "modified");
150 deleteFile("file.txt"); 169 deleteFile("file.txt");
170
171 allowModifyEvent("file.txt");
151 expectRemoveEvent("file.txt"); 172 expectRemoveEvent("file.txt");
152 }); 173 });
153 174
154 test("reports an add when a file is added and then immediately modified", 175 test("reports an add when a file is added and then immediately modified",
155 () { 176 () {
156 startWatcher(); 177 startWatcher();
157 178
158 writeFile("file.txt"); 179 writeFile("file.txt");
159 writeFile("file.txt", contents: "modified"); 180 writeFile("file.txt", contents: "modified");
181
160 expectAddEvent("file.txt"); 182 expectAddEvent("file.txt");
183 startClosingEventStream();
184 allowModifyEvent("file.txt");
161 }); 185 });
162 }); 186 });
163 187
164 group("subdirectories", () { 188 group("subdirectories", () {
165 test('watches files in subdirectories', () { 189 test('watches files in subdirectories', () {
166 startWatcher(); 190 startWatcher();
167 writeFile("a/b/c/d/file.txt"); 191 writeFile("a/b/c/d/file.txt");
168 expectAddEvent("a/b/c/d/file.txt"); 192 expectAddEvent("a/b/c/d/file.txt");
169 }); 193 });
170 194
171 test('notifies when a subdirectory is moved within the watched directory ' 195 test('notifies when a subdirectory is moved within the watched directory '
172 'and then its contents are modified', () { 196 'and then its contents are modified', () {
173 writeFile("old/file.txt"); 197 writeFile("old/file.txt");
174 startWatcher(); 198 startWatcher();
175 199
176 renameDir("old", "new"); 200 renameDir("old", "new");
177 inAnyOrder(() { 201 inAnyOrder([
178 expectRemoveEvent("old/file.txt"); 202 isRemoveEvent("old/file.txt"),
179 expectAddEvent("new/file.txt"); 203 isAddEvent("new/file.txt"),
Bob Nystrom 2014/01/09 00:34:22 Ditch trailing ",".
nweiz 2014/01/09 21:59:20 Done.
180 }); 204 ]);
181 205
182 writeFile("new/file.txt", contents: "modified"); 206 writeFile("new/file.txt", contents: "modified");
183 expectModifyEvent("new/file.txt"); 207 expectModifyEvent("new/file.txt");
184 }); 208 });
185 209
186 test('emits events for many nested files added at once', () { 210 test('emits events for many nested files added at once', () {
187 withPermutations((i, j, k) => 211 withPermutations((i, j, k) =>
188 writeFile("sub/sub-$i/sub-$j/file-$k.txt")); 212 writeFile("sub/sub-$i/sub-$j/file-$k.txt"));
189 213
190 createDir("dir"); 214 createDir("dir");
191 startWatcher(dir: "dir"); 215 startWatcher(dir: "dir");
192 renameDir("sub", "dir/sub"); 216 renameDir("sub", "dir/sub");
193 217
194 inAnyOrder(() { 218 inAnyOrder(withPermutations((i, j, k) =>
195 withPermutations((i, j, k) => 219 isAddEvent("dir/sub/sub-$i/sub-$j/file-$k.txt")));
196 expectAddEvent("dir/sub/sub-$i/sub-$j/file-$k.txt"));
197 });
198 }); 220 });
199 221
200 test('emits events for many nested files removed at once', () { 222 test('emits events for many nested files removed at once', () {
201 withPermutations((i, j, k) => 223 withPermutations((i, j, k) =>
202 writeFile("dir/sub/sub-$i/sub-$j/file-$k.txt")); 224 writeFile("dir/sub/sub-$i/sub-$j/file-$k.txt"));
203 225
204 createDir("dir"); 226 createDir("dir");
205 startWatcher(dir: "dir"); 227 startWatcher(dir: "dir");
206 228
207 // Rename the directory rather than deleting it because native watchers 229 // Rename the directory rather than deleting it because native watchers
208 // report a rename as a single DELETE event for the directory, whereas 230 // report a rename as a single DELETE event for the directory, whereas
209 // they report recursive deletion with DELETE events for every file in the 231 // they report recursive deletion with DELETE events for every file in the
210 // directory. 232 // directory.
211 renameDir("dir/sub", "sub"); 233 renameDir("dir/sub", "sub");
212 234
213 inAnyOrder(() { 235 inAnyOrder(withPermutations((i, j, k) =>
214 withPermutations((i, j, k) => 236 isRemoveEvent("dir/sub/sub-$i/sub-$j/file-$k.txt")));
215 expectRemoveEvent("dir/sub/sub-$i/sub-$j/file-$k.txt"));
216 });
217 }); 237 });
218 238
219 test('emits events for many nested files moved at once', () { 239 test('emits events for many nested files moved at once', () {
220 withPermutations((i, j, k) => 240 withPermutations((i, j, k) =>
221 writeFile("dir/old/sub-$i/sub-$j/file-$k.txt")); 241 writeFile("dir/old/sub-$i/sub-$j/file-$k.txt"));
222 242
223 createDir("dir"); 243 createDir("dir");
224 startWatcher(dir: "dir"); 244 startWatcher(dir: "dir");
225 renameDir("dir/old", "dir/new"); 245 renameDir("dir/old", "dir/new");
226 246
227 inAnyOrder(() { 247 inAnyOrder(unionAll(withPermutations((i, j, k) {
228 withPermutations((i, j, k) { 248 return new Set.from([
229 expectRemoveEvent("dir/old/sub-$i/sub-$j/file-$k.txt"); 249 isRemoveEvent("dir/old/sub-$i/sub-$j/file-$k.txt"),
230 expectAddEvent("dir/new/sub-$i/sub-$j/file-$k.txt"); 250 isAddEvent("dir/new/sub-$i/sub-$j/file-$k.txt"),
231 }); 251 ]);
232 }); 252 })));
233 }); 253 });
234 254
235 test("emits events for many files added at once in a subdirectory with the " 255 test("emits events for many files added at once in a subdirectory with the "
236 "same name as a removed file", () { 256 "same name as a removed file", () {
237 writeFile("dir/sub"); 257 writeFile("dir/sub");
238 withPermutations((i, j, k) => 258 withPermutations((i, j, k) =>
239 writeFile("old/sub-$i/sub-$j/file-$k.txt")); 259 writeFile("old/sub-$i/sub-$j/file-$k.txt"));
240 startWatcher(dir: "dir"); 260 startWatcher(dir: "dir");
241 261
242 deleteFile("dir/sub"); 262 deleteFile("dir/sub");
243 renameDir("old", "dir/sub"); 263 renameDir("old", "dir/sub");
244 inAnyOrder(() { 264
245 expectRemoveEvent("dir/sub"); 265 var events = withPermutations((i, j, k) =>
246 withPermutations((i, j, k) => 266 isAddEvent("dir/sub/sub-$i/sub-$j/file-$k.txt"));
247 expectAddEvent("dir/sub/sub-$i/sub-$j/file-$k.txt")); 267 events.add(isRemoveEvent("dir/sub"));
248 }); 268 inAnyOrder(events);
249 }); 269 });
250 }); 270 });
251 } 271 }
OLDNEW
« no previous file with comments | « pkg/watcher/test/directory_watcher/mac_os_test.dart ('k') | pkg/watcher/test/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698