[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 https://github.com/flutter/flutter/issues/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.
diff --git a/engine/src/flutter/runtime/fixtures/runtime_test.dart b/engine/src/flutter/runtime/fixtures/runtime_test.dart
index 3f2cbaf..6f823c1 100644
--- a/engine/src/flutter/runtime/fixtures/runtime_test.dart
+++ b/engine/src/flutter/runtime/fixtures/runtime_test.dart
@@ -97,8 +97,8 @@
if (!await exits.moveNext()) {
throw AssertionError('Failed to receive onExit');
}
- messages.cancel();
- exits.cancel();
+ await messages.cancel();
+ await exits.cancel();
}
Future<void> testUnsuccessfullIsolateLaunch() async {
@@ -121,7 +121,7 @@
// The root isolate will not run an eventloop, so we have to run the actual
// test in an isolate.
- Isolate.spawn(mainTest, null);
+ unawaited(Isolate.spawn(mainTest, null));
}
@pragma('vm:external-name', 'MakeNextIsolateSpawnFail')
diff --git a/engine/src/flutter/shell/common/fixtures/shell_test.dart b/engine/src/flutter/shell/common/fixtures/shell_test.dart
index 6c54545..124d6ad 100644
--- a/engine/src/flutter/shell/common/fixtures/shell_test.dart
+++ b/engine/src/flutter/shell/common/fixtures/shell_test.dart
@@ -604,7 +604,7 @@
void testSemanticsActions() {
PlatformDispatcher.instance.onSemanticsActionEvent = (SemanticsActionEvent action) async {
await null;
- Future<void>.value().then((_) {
+ await Future<void>.value().then((_) {
notifyNative();
});
};
@@ -614,7 +614,7 @@
void testPointerActions() {
PlatformDispatcher.instance.onPointerDataPacket = (PointerDataPacket pointer) async {
await null;
- Future<void>.value().then((_) {
+ await Future<void>.value().then((_) {
notifyNative();
});
};
diff --git a/engine/src/flutter/testing/dart/channel_buffers_test.dart b/engine/src/flutter/testing/dart/channel_buffers_test.dart
index 2007d94..a6bd8a9 100644
--- a/engine/src/flutter/testing/dart/channel_buffers_test.dart
+++ b/engine/src/flutter/testing/dart/channel_buffers_test.dart
@@ -56,13 +56,17 @@
});
log.add('before drain');
- buffers.drain(channel, (
- ByteData? drainedData,
- ui.PlatformMessageResponseCallback drainedCallback,
- ) async {
- log.add('callback');
- completer.complete();
- });
+ // Ignoring the returned future because the completion of the drain is
+ // communicated using the `completer`.
+ unawaited(
+ buffers.drain(channel, (
+ ByteData? drainedData,
+ ui.PlatformMessageResponseCallback drainedCallback,
+ ) async {
+ log.add('callback');
+ completer.complete();
+ }),
+ );
log.add('after drain, before await');
await completer.future;
log.add('after await');
diff --git a/engine/src/flutter/testing/dart/http_allow_http_connections_test.dart b/engine/src/flutter/testing/dart/http_allow_http_connections_test.dart
index 5c5f2e4..98856f3 100644
--- a/engine/src/flutter/testing/dart/http_allow_http_connections_test.dart
+++ b/engine/src/flutter/testing/dart/http_allow_http_connections_test.dart
@@ -20,7 +20,7 @@
test('We can ban HTTP explicitly.', () async {
final String host = await getLocalHostIP();
await bindServerAndTest(host, (HttpClient httpClient, Uri uri) async {
- asyncExpectThrows<UnsupportedError>(
+ await asyncExpectThrows<UnsupportedError>(
() async => runZoned(
() => httpClient.getUrl(uri),
zoneValues: <dynamic, dynamic>{#flutter.io.allow_http: false},
diff --git a/engine/src/flutter/testing/dart/http_disallow_http_connections_test.dart b/engine/src/flutter/testing/dart/http_disallow_http_connections_test.dart
index 57fd1c0..d39cdc0 100644
--- a/engine/src/flutter/testing/dart/http_disallow_http_connections_test.dart
+++ b/engine/src/flutter/testing/dart/http_disallow_http_connections_test.dart
@@ -59,14 +59,14 @@
void main() {
test('testWithLocalIP', () async {
await bindServerAndTest(await getLocalHostIP(), (HttpClient httpClient, Uri httpUri) async {
- asyncExpectThrows<UnsupportedError>(() async => httpClient.getUrl(httpUri));
- asyncExpectThrows<UnsupportedError>(
+ await asyncExpectThrows<UnsupportedError>(() async => httpClient.getUrl(httpUri));
+ await asyncExpectThrows<UnsupportedError>(
() async => runZoned(
() => httpClient.getUrl(httpUri),
zoneValues: <dynamic, dynamic>{#flutter.io.allow_http: 'foo'},
),
);
- asyncExpectThrows<UnsupportedError>(
+ await asyncExpectThrows<UnsupportedError>(
() async => runZoned(
() => httpClient.getUrl(httpUri),
zoneValues: <dynamic, dynamic>{#flutter.io.allow_http: false},
@@ -81,10 +81,10 @@
test('testWithHostname', () async {
await bindServerAndTest(Platform.localHostname, (HttpClient httpClient, Uri httpUri) async {
- asyncExpectThrows<UnsupportedError>(() async => httpClient.getUrl(httpUri));
+ await asyncExpectThrows<UnsupportedError>(() async => httpClient.getUrl(httpUri));
final mockFoo = _MockZoneValue('foo');
- asyncExpectThrows<UnsupportedError>(
+ await asyncExpectThrows<UnsupportedError>(
() async => runZoned(
() => httpClient.getUrl(httpUri),
zoneValues: <dynamic, dynamic>{#flutter.io.allow_http: mockFoo},
@@ -93,7 +93,7 @@
expect(mockFoo.checked, isTrue);
final mockFalse = _MockZoneValue(false);
- asyncExpectThrows<UnsupportedError>(
+ await asyncExpectThrows<UnsupportedError>(
() async => runZoned(
() => httpClient.getUrl(httpUri),
zoneValues: <dynamic, dynamic>{#flutter.io.allow_http: mockFalse},
diff --git a/engine/src/flutter/testing/ios_scenario_app/bin/run_ios_tests.dart b/engine/src/flutter/testing/ios_scenario_app/bin/run_ios_tests.dart
index 1e3243a..6a1aca6 100644
--- a/engine/src/flutter/testing/ios_scenario_app/bin/run_ios_tests.dart
+++ b/engine/src/flutter/testing/ios_scenario_app/bin/run_ios_tests.dart
@@ -56,30 +56,32 @@
// Run the actual script.
final completer = Completer<void>();
- runZonedGuarded(
- () async {
- await _run(
- cleanup,
- engine,
- iosEngineVariant: iosEngineVariant,
- deviceName: results.option('device-name')!,
- deviceIdentifier: results.option('device-identifier')!,
- osRuntime: results.option('os-runtime')!,
- osVersion: results.option('os-version')!,
- dumpXcresultOnFailure: dumpXcresultOnFailurePath,
- );
- completer.complete();
- },
- (e, s) {
- if (e is _ToolFailure) {
- io.stderr.writeln(e);
- io.exitCode = 1;
- } else {
- io.stderr.writeln('Uncaught exception: $e\n$s');
- io.exitCode = 255;
- }
- completer.complete();
- },
+ unawaited(
+ runZonedGuarded(
+ () async {
+ await _run(
+ cleanup,
+ engine,
+ iosEngineVariant: iosEngineVariant,
+ deviceName: results.option('device-name')!,
+ deviceIdentifier: results.option('device-identifier')!,
+ osRuntime: results.option('os-runtime')!,
+ osVersion: results.option('os-version')!,
+ dumpXcresultOnFailure: dumpXcresultOnFailurePath,
+ );
+ completer.complete();
+ },
+ (e, s) {
+ if (e is _ToolFailure) {
+ io.stderr.writeln(e);
+ io.exitCode = 1;
+ } else {
+ io.stderr.writeln('Uncaught exception: $e\n$s');
+ io.exitCode = 255;
+ }
+ completer.complete();
+ },
+ ),
);
// We can't await the result of runZonedGuarded becauase async errors in futures never cross different errorZone boundaries.
diff --git a/engine/src/flutter/tools/android_lint/bin/main.dart b/engine/src/flutter/tools/android_lint/bin/main.dart
index d42df29..d812eed 100644
--- a/engine/src/flutter/tools/android_lint/bin/main.dart
+++ b/engine/src/flutter/tools/android_lint/bin/main.dart
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+import 'dart:async';
import 'dart:io';
import 'package:args/args.dart';
@@ -156,8 +157,8 @@
lintArgs,
environment: <String, String>{'JAVA_HOME': javahome},
);
- lintProcess.stdout.pipe(stdout);
- lintProcess.stderr.pipe(stderr);
+ unawaited(lintProcess.stdout.pipe(stdout));
+ unawaited(lintProcess.stderr.pipe(stderr));
return lintProcess.exitCode;
}
diff --git a/engine/src/flutter/tools/gen_web_locale_keymap/lib/github.dart b/engine/src/flutter/tools/gen_web_locale_keymap/lib/github.dart
index 717a40f..b890067 100644
--- a/engine/src/flutter/tools/gen_web_locale_keymap/lib/github.dart
+++ b/engine/src/flutter/tools/gen_web_locale_keymap/lib/github.dart
@@ -102,7 +102,7 @@
} catch (exception) {
print('Error writing GitHub cache. Details: $exception');
} finally {
- sink?.close();
+ await sink?.close();
}
return result;
}
diff --git a/engine/src/flutter/tools/mcp/test/server_test.dart b/engine/src/flutter/tools/mcp/test/server_test.dart
index f23faa5..37233bf 100644
--- a/engine/src/flutter/tools/mcp/test/server_test.dart
+++ b/engine/src/flutter/tools/mcp/test/server_test.dart
@@ -42,7 +42,7 @@
expect(json['result']['tools'], isNotEmpty, reason: outputString);
await inputController.close();
- server.shutdown();
+ await server.shutdown();
});
test('build', () async {
@@ -90,7 +90,7 @@
expect(json['result']['content'][0]['text'], equals('Build succeeded.'), reason: outputString);
await inputController.close();
- server.shutdown();
+ await server.shutdown();
});
test('list targets', () async {
@@ -136,6 +136,6 @@
expect(json['result']['content'][0]['text'], equals('//foo\n//bar\n'), reason: outputString);
await inputController.close();
- server.shutdown();
+ await server.shutdown();
});
}