added unawaited function for devicelab and turned on unawaited_futures linter (#82833)

This commit is contained in:
gaaclarke
2021-05-18 14:19:03 -07:00
committed by GitHub
parent 5c09eecd0d
commit 7cdd33fe99
23 changed files with 74 additions and 33 deletions

View File

@@ -0,0 +1,14 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// Indicates to the linter that the given future is intentionally not awaited.
///
/// Has the same functionality as `unawaited` from `package:pedantic`.
///
/// In an async context, it is normally expected than all Futures are awaited,
/// and that is the basis of the lint unawaited_futures which is turned on for
/// the flutter_tools package. However, there are times where one or more
/// futures are intentionally not awaited. This function may be used to ignore a
/// particular future. It silences the unawaited_futures lint.
void unawaited(Future<void> future) { }

View File

@@ -7,6 +7,7 @@ import 'dart:convert';
import 'dart:io';
import 'dart:math' as math;
import 'package:flutter_devicelab/common.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
@@ -591,13 +592,13 @@ class AndroidDevice extends Device {
.listen((String line) {
print('adb logcat stderr: $line');
}, onDone: () { stderrDone.complete(); });
process.exitCode.then<void>((int exitCode) {
unawaited(process.exitCode.then<void>((int exitCode) {
print('adb logcat process terminated with exit code $exitCode');
if (!aborted) {
stream.addError(BuildFailedError('adb logcat failed with exit code $exitCode.\n'));
processDone.complete();
}
});
}));
await Future.any<dynamic>(<Future<dynamic>>[
Future.wait<void>(<Future<void>>[
stdoutDone.future,

View File

@@ -7,6 +7,7 @@ import 'dart:convert' show json, utf8, LineSplitter, JsonEncoder;
import 'dart:io' as io;
import 'dart:math' as math;
import 'package:flutter_devicelab/common.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
@@ -625,9 +626,9 @@ Future<io.Process> _spawnChromiumProcess(String executable, List<String> args, {
// A precaution that avoids accumulating browser processes, in case the
// glibc bug doesn't cause the browser to quit and we keep looping and
// launching more processes.
process.exitCode.timeout(const Duration(seconds: 1), onTimeout: () {
unawaited(process.exitCode.timeout(const Duration(seconds: 1), onTimeout: () {
process.kill();
return null;
});
}));
}
}

View File

@@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter_devicelab/common.dart';
import 'package:meta/meta.dart';
import 'package:vm_service/vm_service.dart';
@@ -103,9 +104,9 @@ Future<TaskResult> runTask(
bool runnerFinished = false;
runner.exitCode.whenComplete(() {
unawaited(runner.exitCode.whenComplete(() {
runnerFinished = true;
});
}));
final Completer<Uri> uri = Completer<Uri>();

View File

@@ -7,6 +7,7 @@ import 'dart:convert';
import 'dart:io';
import 'dart:math' as math;
import 'package:flutter_devicelab/common.dart';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
@@ -291,10 +292,10 @@ Future<Process> startProcess(
final ProcessInfo processInfo = ProcessInfo(command, process);
_runningProcesses.add(processInfo);
process.exitCode.then<void>((int exitCode) {
unawaited(process.exitCode.then<void>((int exitCode) {
print('"$executable" exit code: $exitCode');
_runningProcesses.remove(processInfo);
});
}));
return process;
}

View File

@@ -5,6 +5,7 @@
import 'dart:io';
import 'package:args/args.dart';
import 'package:flutter_devicelab/common.dart';
import '../framework/adb.dart';
import '../framework/task_result.dart';
@@ -106,7 +107,7 @@ abstract class BuildTestTask {
}
if (!testOnly) {
build();
unawaited(build());
}
if (buildOnly) {

View File

@@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter_devicelab/common.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/task_result.dart';
import 'package:flutter_devicelab/framework/utils.dart';
@@ -168,7 +169,7 @@ class PluginPlatformInterfaceMacOS {
section('Wait for registry execution after hot restart');
await registryExecutedCompleter.future;
subscription.cancel();
unawaited(subscription.cancel());
run.kill();
});
return TaskResult.success(null);

View File

@@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:convert' show json;
import 'dart:io' as io;
import 'package:flutter_devicelab/common.dart';
import 'package:flutter_devicelab/framework/browser.dart';
import 'package:flutter_devicelab/framework/task_result.dart';
import 'package:flutter_devicelab/framework/utils.dart';
@@ -58,7 +59,7 @@ Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async {
'Requested to run bechmark ${benchmarkIterator.current}, but '
'got results for $benchmarkName.',
));
server.close();
unawaited(server.close());
}
// Trace data is null when the benchmark is not frame-based, such as RawRecorder.
@@ -80,7 +81,7 @@ Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async {
return Response.ok('Stopped performance tracing');
} else if (request.requestedUri.path.endsWith('/on-error')) {
final Map<String, dynamic> errorDetails = json.decode(await request.readAsString()) as Map<String, dynamic>;
server.close();
unawaited(server.close());
// Keep the stack trace as a string. It's thrown in the browser, not this Dart VM.
profileData.completeError('${errorDetails['error']}\n${errorDetails['stackTrace']}');
return Response.ok('');
@@ -183,7 +184,7 @@ Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async {
}
return TaskResult.success(taskResult, benchmarkScoreKeys: benchmarkScoreKeys);
} finally {
server?.close();
unawaited(server?.close());
chrome?.stop();
}
});