Skip to content

Commit c4bd753

Browse files
authored
Fix test passing issues (#2424)
* Do not trap exceptions there; looks like the odd behavior that tried to work around is fixed * Fix test passing issues * Fix default for glob context * dartfmt
1 parent 85ae869 commit c4bd753

File tree

15 files changed

+60
-30
lines changed

15 files changed

+60
-30
lines changed

lib/src/io_utils.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,26 @@ class MultiFutureTracker<T> {
122122
/// Wait until fewer or equal to this many Futures are outstanding.
123123
Future<void> _waitUntil(int max) async {
124124
while (_trackedFutures.length > max) {
125-
try {
126-
await Future.any(_trackedFutures);
127-
// The empty catch is OK because we're just counting future completions
128-
// and we don't care about errors (the original caller of
129-
// addFutureToClosure is responsible for those).
130-
} catch (e) {} // ignore: empty_catches
125+
await Future.any(_trackedFutures);
131126
}
132127
}
133128

134129
/// Generates a [Future] from the given closure and adds it to the queue,
135130
/// once the queue is sufficiently empty. The returned future completes
136131
/// when the generated [Future] has been added to the queue.
132+
///
133+
/// If the closure does not handle its own exceptions, other calls to
134+
/// [addFutureFromClosure] or [wait] may trigger an exception.
137135
Future<void> addFutureFromClosure(Future<T> Function() closure) async {
138136
await _waitUntil(parallel - 1);
139137
Future<void> future = closure();
140138
_trackedFutures.add(future);
141139
// ignore: unawaited_futures
142-
future.then((f) => _trackedFutures.remove(future),
143-
onError: (s, e) => _trackedFutures.remove(future));
140+
future.then((f) {
141+
_trackedFutures.remove(future);
142+
}, onError: (s, e) {
143+
_trackedFutures.remove(future);
144+
});
144145
}
145146

146147
/// Wait until all futures added so far have completed.

lib/src/model_utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ bool matchGlobs(List<String> globs, String fullName, {bool isWindows}) {
5252
}
5353

5454
return filteredGlobs.any((g) =>
55-
Glob(g, context: isWindows ? path.windows : null).matches(fullName));
55+
Glob(g, context: isWindows ? path.windows : path.posix)
56+
.matches(fullName));
5657
}
5758

5859
/// Returns the [AstNode] for a given [Element].

test/io_utils_test.dart

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,31 @@ void main() {
2424
/// [MultiFutureTracker.addFutureFromClosure].
2525
test('no deadlock when delayed exceptions fire in closures', () async {
2626
var sharedTracker = MultiFutureTracker(2);
27-
var t =
28-
Future.delayed(Duration(milliseconds: 10), () => throw Exception());
29-
await sharedTracker.addFutureFromClosure(() => t);
30-
expect(t, throwsA(const TypeMatcher<Exception>()));
31-
var u =
32-
Future.delayed(Duration(milliseconds: 10), () => throw Exception());
33-
await sharedTracker.addFutureFromClosure(() => u);
34-
expect(u, throwsA(const TypeMatcher<Exception>()));
35-
var v =
36-
Future.delayed(Duration(milliseconds: 10), () => throw Exception());
37-
await sharedTracker.addFutureFromClosure(() => v);
38-
expect(v, throwsA(const TypeMatcher<Exception>()));
27+
expect(() async {
28+
var t =
29+
Future.delayed(Duration(milliseconds: 10), () => throw Exception());
30+
await sharedTracker.addFutureFromClosure(() => t);
31+
return t;
32+
}, throwsA(const TypeMatcher<Exception>()));
33+
expect(() async {
34+
var t =
35+
Future.delayed(Duration(milliseconds: 10), () => throw Exception());
36+
await sharedTracker.addFutureFromClosure(() => t);
37+
return t;
38+
}, throwsA(const TypeMatcher<Exception>()));
39+
expect(() async {
40+
var t =
41+
Future.delayed(Duration(milliseconds: 10), () => throw Exception());
42+
// ignore: empty_catches
43+
await sharedTracker.addFutureFromClosure(() => t);
44+
return t;
45+
}, throwsA(const TypeMatcher<Exception>()));
46+
expect(() async {
47+
var t =
48+
Future.delayed(Duration(milliseconds: 10), () => throw Exception());
49+
await sharedTracker.addFutureFromClosure(() => t);
50+
return t;
51+
}, throwsA(const TypeMatcher<Exception>()));
3952

4053
/// We deadlock here if the exception is not handled properly.
4154
await sharedTracker.wait();
@@ -55,8 +68,12 @@ void main() {
5568
var completed = <int>{};
5669
var tracker = MultiFutureTracker(1);
5770
await tracker.addFutureFromClosure(() async => completed.add(0));
58-
await tracker.addFutureFromClosure(() async => throw Exception());
59-
await tracker.addFutureFromClosure(() async => throw Exception());
71+
await tracker
72+
.addFutureFromClosure(() async => throw Exception())
73+
.catchError((e) {});
74+
await tracker
75+
.addFutureFromClosure(() async => throw Exception())
76+
.catchError((e) {});
6077
await tracker.addFutureFromClosure(() async => completed.add(3));
6178
await tracker.wait();
6279
expect(completed.length, equals(2));

testing/sky_engine/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
name: sky_engine
22
description: package with embedder yaml
33
version: 0.0.1
4+
environment:
5+
sdk: '>=2.0.0 <3.0.0'

testing/test_package_bad/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
name: test_package_bad
22
description: Best package ever.
33
version: 0.0.1
4+
environment:
5+
sdk: '>=2.0.0 <3.0.0'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: test_package_custom_templates
22
version: 0.0.1
33
description: A simple console application.
4+
environment:
5+
sdk: '>=2.0.0 <3.0.0'
46
#dependencies:
57
# foo_bar: '>=1.0.0 <2.0.0'

testing/test_package_doc_errors/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ name: test_package_doc_errors
22
version: 0.0.1
33
description: A simple console application.
44
environment:
5-
sdk: <=3.0.0
5+
sdk: '>=2.0.0 <3.0.0'
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: test_package_experiments
22
version: 0.0.1
3-
sdk: '>=2.9.0-dev.0 <2.10.0'
3+
environment:
4+
sdk: '>=2.10.0-0 <3.0.0'
45
description: Experimental flags are tested here.

testing/test_package_export_error/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ name: test_package_export_error
22
version: 0.0.1
33
description: A simple console application.
44
environment:
5-
sdk: <=3.0.0
5+
sdk: '>=2.0.0 <3.0.0'

testing/test_package_extensions/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ name: test_package_extensions
22
version: 0.0.1
33
description: A simple console application.
44
environment:
5-
sdk: <=3.0.0
5+
sdk: '>=2.0.0 <3.0.0'

0 commit comments

Comments
 (0)