Fix flakiness of commands_test (#11705)
- Wait for full Hot Reload - Wait for full Restart - Fallback if checkHealth throws METHOD_NOT_FOUND. We try to wait for the service extensions to be registered and retry.
This commit is contained in:
parent
79d08f683a
commit
937b98e1b9
@ -77,15 +77,21 @@ void main() {
|
||||
await driver.drive('none');
|
||||
final Future<String> reloadStartingText =
|
||||
stdout.stream.firstWhere((String line) => line.endsWith('hot reload...'));
|
||||
final Future<String> reloadEndingText =
|
||||
stdout.stream.firstWhere((String line) => line.contains('Hot reload performed in '));
|
||||
print('test: pressing "r" to perform a hot reload...');
|
||||
run.stdin.write('r');
|
||||
await reloadStartingText;
|
||||
await reloadEndingText;
|
||||
await driver.drive('none');
|
||||
final Future<String> restartStartingText =
|
||||
stdout.stream.firstWhere((String line) => line.endsWith('full restart...'));
|
||||
final Future<String> restartEndingText =
|
||||
stdout.stream.firstWhere((String line) => line.contains('Restart performed in '));
|
||||
print('test: pressing "R" to perform a full reload...');
|
||||
run.stdin.write('R');
|
||||
await restartStartingText;
|
||||
await restartEndingText;
|
||||
await driver.drive('none');
|
||||
run.stdin.write('q');
|
||||
final int result = await run.exitCode;
|
||||
|
@ -125,7 +125,6 @@ tasks:
|
||||
Runs tests of flutter run commands.
|
||||
stage: devicelab
|
||||
required_agent_capabilities: ["has-android-device"]
|
||||
flaky: true
|
||||
|
||||
android_sample_catalog_generator:
|
||||
description: >
|
||||
|
@ -7,6 +7,7 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:file/file.dart' as f;
|
||||
import 'package:json_rpc_2/error_code.dart' as error_code;
|
||||
import 'package:json_rpc_2/json_rpc_2.dart' as rpc;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
@ -207,10 +208,6 @@ class FlutterDriver {
|
||||
});
|
||||
}
|
||||
|
||||
// Attempt to resume isolate if it was paused
|
||||
if (isolate.pauseEvent is VMPauseStartEvent) {
|
||||
_log.trace('Isolate is paused at start.');
|
||||
|
||||
// Waits for a signal from the VM service that the extension is registered
|
||||
Future<String> waitForServiceExtension() {
|
||||
return isolate.onExtensionAdded.firstWhere((String extension) {
|
||||
@ -231,6 +228,10 @@ class FlutterDriver {
|
||||
});
|
||||
}
|
||||
|
||||
// Attempt to resume isolate if it was paused
|
||||
if (isolate.pauseEvent is VMPauseStartEvent) {
|
||||
_log.trace('Isolate is paused at start.');
|
||||
|
||||
// If the isolate is paused at the start, e.g. via the --start-paused
|
||||
// option, then the VM service extension is not registered yet. Wait for
|
||||
// it to be registered.
|
||||
@ -269,8 +270,27 @@ class FlutterDriver {
|
||||
);
|
||||
}
|
||||
|
||||
// Invoked checkHealth and try to fix delays in the registration of Service
|
||||
// extensions
|
||||
Future<Health> checkHealth() async {
|
||||
try {
|
||||
// At this point the service extension must be installed. Verify it.
|
||||
final Health health = await driver.checkHealth();
|
||||
return await driver.checkHealth();
|
||||
} on rpc.RpcException catch (e) {
|
||||
if (e.code != error_code.METHOD_NOT_FOUND) {
|
||||
rethrow;
|
||||
}
|
||||
_log.trace(
|
||||
'Check Health failed, try to wait for the service extensions to be'
|
||||
'registered.'
|
||||
);
|
||||
await enableIsolateStreams();
|
||||
await waitForServiceExtension().timeout(_kLongTimeout * 2);
|
||||
return driver.checkHealth();
|
||||
}
|
||||
}
|
||||
|
||||
final Health health = await checkHealth();
|
||||
if (health.status != HealthStatus.ok) {
|
||||
await client.close();
|
||||
throw new DriverError('Flutter application health check failed.');
|
||||
|
Loading…
x
Reference in New Issue
Block a user