Delinting future awaits round 3 (#10791)
* round 3 * partially address comments * merge * review notes * review * review * review
This commit is contained in:
parent
8475e0b290
commit
e28765a997
@ -42,7 +42,7 @@ const List<String> _kRequiredOptions = const <String>[
|
|||||||
Future<Null> main(List<String> args) async {
|
Future<Null> main(List<String> args) async {
|
||||||
final AppContext executableContext = new AppContext();
|
final AppContext executableContext = new AppContext();
|
||||||
executableContext.setVariable(Logger, new StdoutLogger());
|
executableContext.setVariable(Logger, new StdoutLogger());
|
||||||
executableContext.runInZone(() {
|
await executableContext.runInZone(() {
|
||||||
// Initialize the context with some defaults.
|
// Initialize the context with some defaults.
|
||||||
context.putIfAbsent(Platform, () => const LocalPlatform());
|
context.putIfAbsent(Platform, () => const LocalPlatform());
|
||||||
context.putIfAbsent(FileSystem, () => const LocalFileSystem());
|
context.putIfAbsent(FileSystem, () => const LocalFileSystem());
|
||||||
|
@ -38,7 +38,7 @@ const List<String> _kRequiredOptions = const <String>[
|
|||||||
Future<Null> main(List<String> args) async {
|
Future<Null> main(List<String> args) async {
|
||||||
final AppContext executableContext = new AppContext();
|
final AppContext executableContext = new AppContext();
|
||||||
executableContext.setVariable(Logger, new StdoutLogger());
|
executableContext.setVariable(Logger, new StdoutLogger());
|
||||||
executableContext.runInZone(() {
|
await executableContext.runInZone(() {
|
||||||
// Initialize the context with some defaults.
|
// Initialize the context with some defaults.
|
||||||
context.putIfAbsent(Platform, () => const LocalPlatform());
|
context.putIfAbsent(Platform, () => const LocalPlatform());
|
||||||
context.putIfAbsent(FileSystem, () => const LocalFileSystem());
|
context.putIfAbsent(FileSystem, () => const LocalFileSystem());
|
||||||
|
@ -73,7 +73,7 @@ class LogsCommand extends FlutterCommand {
|
|||||||
|
|
||||||
// Wait for the log reader to be finished.
|
// Wait for the log reader to be finished.
|
||||||
final int result = await exitCompleter.future;
|
final int result = await exitCompleter.future;
|
||||||
subscription.cancel();
|
await subscription.cancel();
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
throwToolExit('Error listening to $logReader logs.');
|
throwToolExit('Error listening to $logReader logs.');
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,8 @@ class RunCommand extends RunCommandBase {
|
|||||||
//
|
//
|
||||||
// Do not add more operations to the future.
|
// Do not add more operations to the future.
|
||||||
final Completer<Null> appStartedTimeRecorder = new Completer<Null>.sync();
|
final Completer<Null> appStartedTimeRecorder = new Completer<Null>.sync();
|
||||||
appStartedTimeRecorder.future.then(
|
// This callback can't throw.
|
||||||
|
appStartedTimeRecorder.future.then( // ignore: unawaited_futures
|
||||||
(_) { appStartedTime = clock.now(); }
|
(_) { appStartedTime = clock.now(); }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -286,7 +286,8 @@ class _DevFSHttpWriter {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (retry < kMaxRetries) {
|
if (retry < kMaxRetries) {
|
||||||
printTrace('Retrying writing "$deviceUri" to DevFS due to error: $e');
|
printTrace('Retrying writing "$deviceUri" to DevFS due to error: $e');
|
||||||
_scheduleWrite(deviceUri, content, retry + 1);
|
// Synchronization is handled by the _completer below.
|
||||||
|
_scheduleWrite(deviceUri, content, retry + 1); // ignore: unawaited_futures
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
printError('Error writing "$deviceUri" to DevFS: $e');
|
printError('Error writing "$deviceUri" to DevFS: $e');
|
||||||
|
@ -142,11 +142,12 @@ Future<String> getCodeSigningIdentityDevelopmentTeam({BuildableIOSApp iosApp, bo
|
|||||||
..close();
|
..close();
|
||||||
|
|
||||||
final String opensslOutput = await UTF8.decodeStream(opensslProcess.stdout);
|
final String opensslOutput = await UTF8.decodeStream(opensslProcess.stdout);
|
||||||
opensslProcess.stderr.drain<String>();
|
// Fire and forget discard of the stderr stream so we don't hold onto resources.
|
||||||
|
// Don't care about the result.
|
||||||
|
opensslProcess.stderr.drain<String>(); // ignore: unawaited_futures
|
||||||
|
|
||||||
if (await opensslProcess.exitCode != 0) {
|
if (await opensslProcess.exitCode != 0)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
return _certificateOrganizationalUnitExtractionPattern
|
return _certificateOrganizationalUnitExtractionPattern
|
||||||
.firstMatch(opensslOutput)
|
.firstMatch(opensslOutput)
|
||||||
|
@ -237,7 +237,7 @@ class IOSSimulator extends Device {
|
|||||||
Future<bool> installApp(ApplicationPackage app) async {
|
Future<bool> installApp(ApplicationPackage app) async {
|
||||||
try {
|
try {
|
||||||
final IOSApp iosApp = app;
|
final IOSApp iosApp = app;
|
||||||
SimControl.instance.install(id, iosApp.simulatorBundlePath);
|
await SimControl.instance.install(id, iosApp.simulatorBundlePath);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
@ -382,7 +382,7 @@ class IOSSimulator extends Device {
|
|||||||
printError('Error waiting for a debug connection: $error');
|
printError('Error waiting for a debug connection: $error');
|
||||||
return new LaunchResult.failed();
|
return new LaunchResult.failed();
|
||||||
} finally {
|
} finally {
|
||||||
observatoryDiscovery.cancel();
|
await observatoryDiscovery.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,7 +556,9 @@ class _IOSSimulatorLogReader extends DeviceLogReader {
|
|||||||
_systemProcess.stderr.transform(UTF8.decoder).transform(const LineSplitter()).listen(_onSystemLine);
|
_systemProcess.stderr.transform(UTF8.decoder).transform(const LineSplitter()).listen(_onSystemLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
_deviceProcess.exitCode.whenComplete(() {
|
// We don't want to wait for the process or its callback. Best effort
|
||||||
|
// cleanup in the callback.
|
||||||
|
_deviceProcess.exitCode.whenComplete(() { // ignore: unawaited_futures
|
||||||
if (_linesController.hasListener)
|
if (_linesController.hasListener)
|
||||||
_linesController.close();
|
_linesController.close();
|
||||||
});
|
});
|
||||||
|
@ -99,8 +99,10 @@ class FlutterDevice {
|
|||||||
if (flutterViews == null || flutterViews.isEmpty)
|
if (flutterViews == null || flutterViews.isEmpty)
|
||||||
return;
|
return;
|
||||||
for (FlutterView view in flutterViews) {
|
for (FlutterView view in flutterViews) {
|
||||||
if (view != null && view.uiIsolate != null)
|
if (view != null && view.uiIsolate != null) {
|
||||||
view.uiIsolate.flutterExit();
|
// Manage waits specifically below.
|
||||||
|
view.uiIsolate.flutterExit(); // ignore: unawaited_futures
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await new Future<Null>.delayed(const Duration(milliseconds: 100));
|
await new Future<Null>.delayed(const Duration(milliseconds: 100));
|
||||||
}
|
}
|
||||||
@ -563,8 +565,9 @@ abstract class ResidentRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Null> stopEchoingDeviceLog() async {
|
Future<Null> stopEchoingDeviceLog() async {
|
||||||
for (FlutterDevice device in flutterDevices)
|
await Future.wait(
|
||||||
device.stopEchoingDeviceLog();
|
flutterDevices.map((FlutterDevice device) => device.stopEchoingDeviceLog())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the [reloadSources] parameter is not null the 'reloadSources' service
|
/// If the [reloadSources] parameter is not null the 'reloadSources' service
|
||||||
@ -591,7 +594,10 @@ abstract class ResidentRunner {
|
|||||||
// Listen for service protocol connection to close.
|
// Listen for service protocol connection to close.
|
||||||
for (FlutterDevice device in flutterDevices) {
|
for (FlutterDevice device in flutterDevices) {
|
||||||
for (VMService service in device.vmServices) {
|
for (VMService service in device.vmServices) {
|
||||||
service.done.then<Null>(
|
// This hooks up callbacks for when the connection stops in the future.
|
||||||
|
// We don't want to wait for them. We don't handle errors in those callbacks'
|
||||||
|
// futures either because they just print to logger and is not critical.
|
||||||
|
service.done.then<Null>( // ignore: unawaited_futures
|
||||||
_serviceProtocolDone,
|
_serviceProtocolDone,
|
||||||
onError: _serviceProtocolError
|
onError: _serviceProtocolError
|
||||||
).whenComplete(_serviceDisconnected);
|
).whenComplete(_serviceDisconnected);
|
||||||
|
@ -42,7 +42,10 @@ class CoverageCollector extends TestWatcher {
|
|||||||
|
|
||||||
final int pid = process.pid;
|
final int pid = process.pid;
|
||||||
int exitCode;
|
int exitCode;
|
||||||
process.exitCode.then<Null>((int code) {
|
// Synchronization is enforced by the API contract. Error handling
|
||||||
|
// synchronization is done in the code below where `exitCode` is checked.
|
||||||
|
// Callback cannot throw.
|
||||||
|
process.exitCode.then<Null>((int code) { // ignore: unawaited_futures
|
||||||
exitCode = code;
|
exitCode = code;
|
||||||
});
|
});
|
||||||
if (exitCode != null)
|
if (exitCode != null)
|
||||||
|
@ -153,7 +153,8 @@ class _FlutterPlatform extends PlatformPlugin {
|
|||||||
bool subprocessActive = false;
|
bool subprocessActive = false;
|
||||||
bool controllerSinkClosed = false;
|
bool controllerSinkClosed = false;
|
||||||
try {
|
try {
|
||||||
controller.sink.done.whenComplete(() { controllerSinkClosed = true; });
|
// Callback can't throw since it's just setting a variable.
|
||||||
|
controller.sink.done.whenComplete(() { controllerSinkClosed = true; }); // ignore: unawaited_futures
|
||||||
|
|
||||||
// Prepare our WebSocket server to talk to the engine subproces.
|
// Prepare our WebSocket server to talk to the engine subproces.
|
||||||
final HttpServer server = await HttpServer.bind(host, 0);
|
final HttpServer server = await HttpServer.bind(host, 0);
|
||||||
@ -272,7 +273,8 @@ class _FlutterPlatform extends PlatformPlugin {
|
|||||||
subprocessActive = false;
|
subprocessActive = false;
|
||||||
final String message = _getErrorMessage(_getExitCodeMessage(exitCode, 'before connecting to test harness'), testPath, shellPath);
|
final String message = _getErrorMessage(_getExitCodeMessage(exitCode, 'before connecting to test harness'), testPath, shellPath);
|
||||||
controller.sink.addError(message);
|
controller.sink.addError(message);
|
||||||
controller.sink.close();
|
// Awaited for with 'sink.done' below.
|
||||||
|
controller.sink.close(); // ignore: unawaited_futures
|
||||||
printTrace('test $ourTestCount: waiting for controller sink to close');
|
printTrace('test $ourTestCount: waiting for controller sink to close');
|
||||||
await controller.sink.done;
|
await controller.sink.done;
|
||||||
break;
|
break;
|
||||||
@ -280,7 +282,8 @@ class _FlutterPlatform extends PlatformPlugin {
|
|||||||
printTrace('test $ourTestCount: timed out waiting for process with pid ${process.pid} to connect to test harness');
|
printTrace('test $ourTestCount: timed out waiting for process with pid ${process.pid} to connect to test harness');
|
||||||
final String message = _getErrorMessage('Test never connected to test harness.', testPath, shellPath);
|
final String message = _getErrorMessage('Test never connected to test harness.', testPath, shellPath);
|
||||||
controller.sink.addError(message);
|
controller.sink.addError(message);
|
||||||
controller.sink.close();
|
// Awaited for with 'sink.done' below.
|
||||||
|
controller.sink.close(); // ignore: unawaited_futures
|
||||||
printTrace('test $ourTestCount: waiting for controller sink to close');
|
printTrace('test $ourTestCount: waiting for controller sink to close');
|
||||||
await controller.sink.done;
|
await controller.sink.done;
|
||||||
break;
|
break;
|
||||||
@ -332,8 +335,10 @@ class _FlutterPlatform extends PlatformPlugin {
|
|||||||
testDone.future.then<_TestResult>((Null _) { return _TestResult.testBailed; }),
|
testDone.future.then<_TestResult>((Null _) { return _TestResult.testBailed; }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
harnessToTest.cancel();
|
await Future.wait(<Future<Null>>[
|
||||||
testToHarness.cancel();
|
harnessToTest.cancel(),
|
||||||
|
testToHarness.cancel(),
|
||||||
|
]);
|
||||||
|
|
||||||
switch (testResult) {
|
switch (testResult) {
|
||||||
case _TestResult.crashed:
|
case _TestResult.crashed:
|
||||||
@ -342,7 +347,8 @@ class _FlutterPlatform extends PlatformPlugin {
|
|||||||
subprocessActive = false;
|
subprocessActive = false;
|
||||||
final String message = _getErrorMessage(_getExitCodeMessage(exitCode, 'before test harness closed its WebSocket'), testPath, shellPath);
|
final String message = _getErrorMessage(_getExitCodeMessage(exitCode, 'before test harness closed its WebSocket'), testPath, shellPath);
|
||||||
controller.sink.addError(message);
|
controller.sink.addError(message);
|
||||||
controller.sink.close();
|
// Awaited for with 'sink.done' below.
|
||||||
|
controller.sink.close(); // ignore: unawaited_futures
|
||||||
printTrace('test $ourTestCount: waiting for controller sink to close');
|
printTrace('test $ourTestCount: waiting for controller sink to close');
|
||||||
await controller.sink.done;
|
await controller.sink.done;
|
||||||
break;
|
break;
|
||||||
@ -384,7 +390,8 @@ class _FlutterPlatform extends PlatformPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!controllerSinkClosed) {
|
if (!controllerSinkClosed) {
|
||||||
controller.sink.close();
|
// Waiting below with await.
|
||||||
|
controller.sink.close(); // ignore: unawaited_futures
|
||||||
printTrace('test $ourTestCount: waiting for controller sink to close');
|
printTrace('test $ourTestCount: waiting for controller sink to close');
|
||||||
await controller.sink.done;
|
await controller.sink.done;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user