Skip to content

Commit 22e75fa

Browse files
authored
[engine] Fix remaining unawaited_futures lints (#193508)
Resolves the remaining `unawaited_futures` lints in `engine/src/flutter/` after `unawaited_futures` was enabled in `analysis_options_common.yaml` (#193125). Part of #168555 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
1 parent fab9915 commit 22e75fa

9 files changed

Lines changed: 56 additions & 49 deletions

File tree

‎engine/src/flutter/runtime/fixtures/runtime_test.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ Future<void> testIsolateStartupFailure() async {
9797
if (!await exits.moveNext()) {
9898
throw AssertionError('Failed to receive onExit');
9999
}
100-
messages.cancel();
101-
exits.cancel();
100+
await messages.cancel();
101+
await exits.cancel();
102102
}
103103

104104
Future<void> testUnsuccessfullIsolateLaunch() async {
@@ -121,7 +121,7 @@ Future<void> testIsolateStartupFailure() async {
121121

122122
// The root isolate will not run an eventloop, so we have to run the actual
123123
// test in an isolate.
124-
Isolate.spawn(mainTest, null);
124+
unawaited(Isolate.spawn(mainTest, null));
125125
}
126126

127127
@pragma('vm:external-name', 'MakeNextIsolateSpawnFail')

‎engine/src/flutter/shell/common/fixtures/shell_test.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ void renderWarmUpView1and2() {
604604
void testSemanticsActions() {
605605
PlatformDispatcher.instance.onSemanticsActionEvent = (SemanticsActionEvent action) async {
606606
await null;
607-
Future<void>.value().then((_) {
607+
await Future<void>.value().then((_) {
608608
notifyNative();
609609
});
610610
};
@@ -614,7 +614,7 @@ void testSemanticsActions() {
614614
void testPointerActions() {
615615
PlatformDispatcher.instance.onPointerDataPacket = (PointerDataPacket pointer) async {
616616
await null;
617-
Future<void>.value().then((_) {
617+
await Future<void>.value().then((_) {
618618
notifyNative();
619619
});
620620
};

‎engine/src/flutter/testing/dart/channel_buffers_test.dart‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ void main() {
5656
});
5757
log.add('before drain');
5858

59-
buffers.drain(channel, (
60-
ByteData? drainedData,
61-
ui.PlatformMessageResponseCallback drainedCallback,
62-
) async {
63-
log.add('callback');
64-
completer.complete();
65-
});
59+
// Ignoring the returned future because the completion of the drain is
60+
// communicated using the `completer`.
61+
unawaited(
62+
buffers.drain(channel, (
63+
ByteData? drainedData,
64+
ui.PlatformMessageResponseCallback drainedCallback,
65+
) async {
66+
log.add('callback');
67+
completer.complete();
68+
}),
69+
);
6670
log.add('after drain, before await');
6771
await completer.future;
6872
log.add('after await');

‎engine/src/flutter/testing/dart/http_allow_http_connections_test.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void main() {
2020
test('We can ban HTTP explicitly.', () async {
2121
final String host = await getLocalHostIP();
2222
await bindServerAndTest(host, (HttpClient httpClient, Uri uri) async {
23-
asyncExpectThrows<UnsupportedError>(
23+
await asyncExpectThrows<UnsupportedError>(
2424
() async => runZoned(
2525
() => httpClient.getUrl(uri),
2626
zoneValues: <dynamic, dynamic>{#flutter.io.allow_http: false},

‎engine/src/flutter/testing/dart/http_disallow_http_connections_test.dart‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ Future<bool> _supportsIPv6() async {
5959
void main() {
6060
test('testWithLocalIP', () async {
6161
await bindServerAndTest(await getLocalHostIP(), (HttpClient httpClient, Uri httpUri) async {
62-
asyncExpectThrows<UnsupportedError>(() async => httpClient.getUrl(httpUri));
63-
asyncExpectThrows<UnsupportedError>(
62+
await asyncExpectThrows<UnsupportedError>(() async => httpClient.getUrl(httpUri));
63+
await asyncExpectThrows<UnsupportedError>(
6464
() async => runZoned(
6565
() => httpClient.getUrl(httpUri),
6666
zoneValues: <dynamic, dynamic>{#flutter.io.allow_http: 'foo'},
6767
),
6868
);
69-
asyncExpectThrows<UnsupportedError>(
69+
await asyncExpectThrows<UnsupportedError>(
7070
() async => runZoned(
7171
() => httpClient.getUrl(httpUri),
7272
zoneValues: <dynamic, dynamic>{#flutter.io.allow_http: false},
@@ -81,10 +81,10 @@ void main() {
8181

8282
test('testWithHostname', () async {
8383
await bindServerAndTest(Platform.localHostname, (HttpClient httpClient, Uri httpUri) async {
84-
asyncExpectThrows<UnsupportedError>(() async => httpClient.getUrl(httpUri));
84+
await asyncExpectThrows<UnsupportedError>(() async => httpClient.getUrl(httpUri));
8585

8686
final mockFoo = _MockZoneValue('foo');
87-
asyncExpectThrows<UnsupportedError>(
87+
await asyncExpectThrows<UnsupportedError>(
8888
() async => runZoned(
8989
() => httpClient.getUrl(httpUri),
9090
zoneValues: <dynamic, dynamic>{#flutter.io.allow_http: mockFoo},
@@ -93,7 +93,7 @@ void main() {
9393
expect(mockFoo.checked, isTrue);
9494

9595
final mockFalse = _MockZoneValue(false);
96-
asyncExpectThrows<UnsupportedError>(
96+
await asyncExpectThrows<UnsupportedError>(
9797
() async => runZoned(
9898
() => httpClient.getUrl(httpUri),
9999
zoneValues: <dynamic, dynamic>{#flutter.io.allow_http: mockFalse},

‎engine/src/flutter/testing/ios_scenario_app/bin/run_ios_tests.dart‎

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,32 @@ void main(List<String> args) async {
5656

5757
// Run the actual script.
5858
final completer = Completer<void>();
59-
runZonedGuarded(
60-
() async {
61-
await _run(
62-
cleanup,
63-
engine,
64-
iosEngineVariant: iosEngineVariant,
65-
deviceName: results.option('device-name')!,
66-
deviceIdentifier: results.option('device-identifier')!,
67-
osRuntime: results.option('os-runtime')!,
68-
osVersion: results.option('os-version')!,
69-
dumpXcresultOnFailure: dumpXcresultOnFailurePath,
70-
);
71-
completer.complete();
72-
},
73-
(e, s) {
74-
if (e is _ToolFailure) {
75-
io.stderr.writeln(e);
76-
io.exitCode = 1;
77-
} else {
78-
io.stderr.writeln('Uncaught exception: $e\n$s');
79-
io.exitCode = 255;
80-
}
81-
completer.complete();
82-
},
59+
unawaited(
60+
runZonedGuarded(
61+
() async {
62+
await _run(
63+
cleanup,
64+
engine,
65+
iosEngineVariant: iosEngineVariant,
66+
deviceName: results.option('device-name')!,
67+
deviceIdentifier: results.option('device-identifier')!,
68+
osRuntime: results.option('os-runtime')!,
69+
osVersion: results.option('os-version')!,
70+
dumpXcresultOnFailure: dumpXcresultOnFailurePath,
71+
);
72+
completer.complete();
73+
},
74+
(e, s) {
75+
if (e is _ToolFailure) {
76+
io.stderr.writeln(e);
77+
io.exitCode = 1;
78+
} else {
79+
io.stderr.writeln('Uncaught exception: $e\n$s');
80+
io.exitCode = 255;
81+
}
82+
completer.complete();
83+
},
84+
),
8385
);
8486

8587
// We can't await the result of runZonedGuarded becauase async errors in futures never cross different errorZone boundaries.

‎engine/src/flutter/tools/android_lint/bin/main.dart‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:async';
56
import 'dart:io';
67

78
import 'package:args/args.dart';
@@ -156,8 +157,8 @@ Future<int> runLint(ArgParser argParser, ArgResults argResults) async {
156157
lintArgs,
157158
environment: <String, String>{'JAVA_HOME': javahome},
158159
);
159-
lintProcess.stdout.pipe(stdout);
160-
lintProcess.stderr.pipe(stderr);
160+
unawaited(lintProcess.stdout.pipe(stdout));
161+
unawaited(lintProcess.stderr.pipe(stderr));
161162
return lintProcess.exitCode;
162163
}
163164

‎engine/src/flutter/tools/gen_web_locale_keymap/lib/github.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Future<String> _tryCached(
102102
} catch (exception) {
103103
print('Error writing GitHub cache. Details: $exception');
104104
} finally {
105-
sink?.close();
105+
await sink?.close();
106106
}
107107
return result;
108108
}

‎engine/src/flutter/tools/mcp/test/server_test.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void main() {
4242
expect(json['result']['tools'], isNotEmpty, reason: outputString);
4343

4444
await inputController.close();
45-
server.shutdown();
45+
await server.shutdown();
4646
});
4747

4848
test('build', () async {
@@ -90,7 +90,7 @@ void main() {
9090
expect(json['result']['content'][0]['text'], equals('Build succeeded.'), reason: outputString);
9191

9292
await inputController.close();
93-
server.shutdown();
93+
await server.shutdown();
9494
});
9595

9696
test('list targets', () async {
@@ -136,6 +136,6 @@ void main() {
136136
expect(json['result']['content'][0]['text'], equals('//foo\n//bar\n'), reason: outputString);
137137

138138
await inputController.close();
139-
server.shutdown();
139+
await server.shutdown();
140140
});
141141
}

0 commit comments

Comments
 (0)