Skip to content

Commit 50dd650

Browse files
committed
Remove backup test assertions.
1 parent f5920a2 commit 50dd650

File tree

5 files changed

+18
-120
lines changed

5 files changed

+18
-120
lines changed

pkgs/watcher/test/directory_watcher/file_tests.dart

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,13 @@ void fileTests() {
141141
});
142142
});
143143

144-
// Most of the time, when multiple filesystem actions happen in sequence,
145-
// they'll be batched together and the watcher will see them all at once.
146-
// These tests verify that the watcher normalizes and combine these events
147-
// properly. However, very occasionally the events will be reported in
148-
// separate batches, and the watcher will report them as though they occurred
149-
// far apart in time, so each of these tests has a "backup case" to allow for
150-
// that as well.
151144
group('clustered changes', () {
152145
test("doesn't notify when a file is created and then immediately removed",
153146
() async {
154147
writeFile('test.txt');
155148
await startWatcher();
156149
writeFile('file.txt');
157150
deleteFile('file.txt');
158-
159-
// Backup case.
160-
startClosingEventStream();
161-
await allowEvents(() {
162-
expectAddEvent('file.txt');
163-
expectRemoveEvent('file.txt');
164-
});
165151
});
166152

167153
test(
@@ -173,13 +159,7 @@ void fileTests() {
173159
deleteFile('file.txt');
174160
writeFile('file.txt', contents: 're-created');
175161

176-
await allowEither(() {
177-
expectModifyEvent('file.txt');
178-
}, () {
179-
// Backup case.
180-
expectRemoveEvent('file.txt');
181-
expectAddEvent('file.txt');
182-
});
162+
await expectModifyEvent('file.txt');
183163
});
184164

185165
test(
@@ -191,14 +171,7 @@ void fileTests() {
191171
renameFile('old.txt', 'new.txt');
192172
writeFile('old.txt', contents: 're-created');
193173

194-
await allowEither(() {
195-
inAnyOrder([isModifyEvent('old.txt'), isAddEvent('new.txt')]);
196-
}, () {
197-
// Backup case.
198-
expectRemoveEvent('old.txt');
199-
expectAddEvent('new.txt');
200-
expectAddEvent('old.txt');
201-
});
174+
await inAnyOrder([isModifyEvent('old.txt'), isAddEvent('new.txt')]);
202175
});
203176

204177
test(
@@ -210,9 +183,6 @@ void fileTests() {
210183
writeFile('file.txt', contents: 'modified');
211184
deleteFile('file.txt');
212185

213-
// Backup case.
214-
await allowModifyEvent('file.txt');
215-
216186
await expectRemoveEvent('file.txt');
217187
});
218188

@@ -224,10 +194,6 @@ void fileTests() {
224194
writeFile('file.txt', contents: 'modified');
225195

226196
await expectAddEvent('file.txt');
227-
228-
// Backup case.
229-
startClosingEventStream();
230-
await allowModifyEvent('file.txt');
231197
});
232198
});
233199

pkgs/watcher/test/directory_watcher/linux_test.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,9 @@ void main() {
3232
renameDir('dir/sub', 'sub');
3333
renameDir('sub', 'dir/sub');
3434

35-
await allowEither(() {
36-
inAnyOrder(withPermutations(
37-
(i, j, k) => isRemoveEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
38-
39-
inAnyOrder(withPermutations(
40-
(i, j, k) => isAddEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
41-
}, () {
42-
inAnyOrder(withPermutations(
43-
(i, j, k) => isModifyEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
44-
});
35+
await inAnyOrder(withPermutations(
36+
(i, j, k) => isRemoveEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
37+
await inAnyOrder(withPermutations(
38+
(i, j, k) => isAddEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
4539
});
4640
}

pkgs/watcher/test/directory_watcher/mac_os_test.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,10 @@ void main() {
4646
renameDir('dir/sub', 'sub');
4747
renameDir('sub', 'dir/sub');
4848

49-
await allowEither(() {
50-
inAnyOrder(withPermutations(
51-
(i, j, k) => isRemoveEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
52-
53-
inAnyOrder(withPermutations(
54-
(i, j, k) => isAddEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
55-
}, () {
56-
inAnyOrder(withPermutations(
57-
(i, j, k) => isModifyEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
58-
});
49+
await inAnyOrder(withPermutations(
50+
(i, j, k) => isRemoveEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
51+
await inAnyOrder(withPermutations(
52+
(i, j, k) => isAddEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
5953
});
6054
test('does not suppress files with the same prefix as a directory', () async {
6155
// Regression test for https://github.com/dart-lang/watcher/issues/83

pkgs/watcher/test/file_watcher/file_tests.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ void fileTests({required bool isNative}) {
1414
});
1515

1616
test("doesn't notify if the file isn't modified", () async {
17-
// TODO(davidmorgan): fix startup race on MacOS.
18-
if (isNative && Platform.isMacOS) {
19-
await Future<void>.delayed(const Duration(milliseconds: 100));
20-
}
2117
await startWatcher(path: 'file.txt');
2218
await expectNoEvents();
2319
});

pkgs/watcher/test/utils.dart

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -164,62 +164,18 @@ void startClosingEventStream() async {
164164
await _watcherEvents.cancel(immediate: true);
165165
}
166166

167-
/// A list of [StreamMatcher]s that have been collected using
168-
/// [_collectStreamMatcher].
169-
List<StreamMatcher>? _collectedStreamMatchers;
170-
171-
/// Collects all stream matchers that are registered within [block] into a
172-
/// single stream matcher.
173-
///
174-
/// The returned matcher will match each of the collected matchers in order.
175-
StreamMatcher _collectStreamMatcher(void Function() block) {
176-
var oldStreamMatchers = _collectedStreamMatchers;
177-
var collectedStreamMatchers = _collectedStreamMatchers = <StreamMatcher>[];
178-
try {
179-
block();
180-
return emitsInOrder(collectedStreamMatchers);
181-
} finally {
182-
_collectedStreamMatchers = oldStreamMatchers;
183-
}
184-
}
185-
186-
/// Either add [streamMatcher] as an expectation to [_watcherEvents], or collect
187-
/// it with [_collectStreamMatcher].
167+
/// Add [streamMatcher] as an expectation to [_watcherEvents].
188168
///
189169
/// [streamMatcher] can be a [StreamMatcher], a [Matcher], or a value.
190-
Future _expectOrCollect(Matcher streamMatcher) {
191-
var collectedStreamMatchers = _collectedStreamMatchers;
192-
if (collectedStreamMatchers != null) {
193-
collectedStreamMatchers.add(emits(streamMatcher));
194-
return Future.sync(() {});
195-
} else {
196-
return expectLater(_watcherEvents, emits(streamMatcher));
197-
}
170+
Future _expect(Matcher streamMatcher) {
171+
return expectLater(_watcherEvents, emits(streamMatcher));
198172
}
199173

200174
/// Expects that [matchers] will match emitted events in any order.
201175
///
202176
/// [matchers] may be [Matcher]s or values, but not [StreamMatcher]s.
203-
Future inAnyOrder(Iterable matchers) {
204-
matchers = matchers.toSet();
205-
return _expectOrCollect(emitsInAnyOrder(matchers));
206-
}
207-
208-
/// Expects that the expectations established in either [block1] or [block2]
209-
/// will match the emitted events.
210-
///
211-
/// If both blocks match, the one that consumed more events will be used.
212-
Future allowEither(void Function() block1, void Function() block2) =>
213-
_expectOrCollect(emitsAnyOf(
214-
[_collectStreamMatcher(block1), _collectStreamMatcher(block2)]));
215-
216-
/// Allows the expectations established in [block] to match the emitted events.
217-
///
218-
/// If the expectations in [block] don't match, no error will be raised and no
219-
/// events will be consumed. If this is used at the end of a test,
220-
/// [startClosingEventStream] should be called before it.
221-
Future allowEvents(void Function() block) =>
222-
_expectOrCollect(mayEmit(_collectStreamMatcher(block)));
177+
Future inAnyOrder(Iterable matchers) =>
178+
_expect(emitsInAnyOrder(matchers.toSet()));
223179

224180
/// Returns a StreamMatcher that matches a [WatchEvent] with the given [type]
225181
/// and [path].
@@ -274,24 +230,16 @@ Future<List<WatchEvent>> takeEvents({required Duration duration}) async {
274230

275231
/// Expects that the next event emitted will be for an add event for [path].
276232
Future expectAddEvent(String path) =>
277-
_expectOrCollect(isWatchEvent(ChangeType.ADD, path));
233+
_expect(isWatchEvent(ChangeType.ADD, path));
278234

279235
/// Expects that the next event emitted will be for a modification event for
280236
/// [path].
281237
Future expectModifyEvent(String path) =>
282-
_expectOrCollect(isWatchEvent(ChangeType.MODIFY, path));
238+
_expect(isWatchEvent(ChangeType.MODIFY, path));
283239

284240
/// Expects that the next event emitted will be for a removal event for [path].
285241
Future expectRemoveEvent(String path) =>
286-
_expectOrCollect(isWatchEvent(ChangeType.REMOVE, path));
287-
288-
/// Consumes a modification event for [path] if one is emitted at this point in
289-
/// the schedule, but doesn't throw an error if it isn't.
290-
///
291-
/// If this is used at the end of a test, [startClosingEventStream] should be
292-
/// called before it.
293-
Future allowModifyEvent(String path) =>
294-
_expectOrCollect(mayEmit(isWatchEvent(ChangeType.MODIFY, path)));
242+
_expect(isWatchEvent(ChangeType.REMOVE, path));
295243

296244
/// Track a fake timestamp to be used when writing files. This always increases
297245
/// so that files that are deleted and re-created do not have their timestamp

0 commit comments

Comments
 (0)