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');
|
await driver.drive('none');
|
||||||
final Future<String> reloadStartingText =
|
final Future<String> reloadStartingText =
|
||||||
stdout.stream.firstWhere((String line) => line.endsWith('hot reload...'));
|
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...');
|
print('test: pressing "r" to perform a hot reload...');
|
||||||
run.stdin.write('r');
|
run.stdin.write('r');
|
||||||
await reloadStartingText;
|
await reloadStartingText;
|
||||||
|
await reloadEndingText;
|
||||||
await driver.drive('none');
|
await driver.drive('none');
|
||||||
final Future<String> restartStartingText =
|
final Future<String> restartStartingText =
|
||||||
stdout.stream.firstWhere((String line) => line.endsWith('full restart...'));
|
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...');
|
print('test: pressing "R" to perform a full reload...');
|
||||||
run.stdin.write('R');
|
run.stdin.write('R');
|
||||||
await restartStartingText;
|
await restartStartingText;
|
||||||
|
await restartEndingText;
|
||||||
await driver.drive('none');
|
await driver.drive('none');
|
||||||
run.stdin.write('q');
|
run.stdin.write('q');
|
||||||
final int result = await run.exitCode;
|
final int result = await run.exitCode;
|
||||||
|
@ -125,7 +125,6 @@ tasks:
|
|||||||
Runs tests of flutter run commands.
|
Runs tests of flutter run commands.
|
||||||
stage: devicelab
|
stage: devicelab
|
||||||
required_agent_capabilities: ["has-android-device"]
|
required_agent_capabilities: ["has-android-device"]
|
||||||
flaky: true
|
|
||||||
|
|
||||||
android_sample_catalog_generator:
|
android_sample_catalog_generator:
|
||||||
description: >
|
description: >
|
||||||
|
@ -7,6 +7,7 @@ import 'dart:convert';
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:file/file.dart' as f;
|
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:json_rpc_2/json_rpc_2.dart' as rpc;
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
@ -207,30 +208,30 @@ class FlutterDriver {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Waits for a signal from the VM service that the extension is registered
|
||||||
|
Future<String> waitForServiceExtension() {
|
||||||
|
return isolate.onExtensionAdded.firstWhere((String extension) {
|
||||||
|
return extension == _kFlutterExtensionMethod;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tells the Dart VM Service to notify us about "Isolate" events.
|
||||||
|
///
|
||||||
|
/// This is a workaround for an issue in package:vm_service_client, which
|
||||||
|
/// subscribes to the "Isolate" stream lazily upon subscription, which
|
||||||
|
/// results in lost events.
|
||||||
|
///
|
||||||
|
/// Details: https://github.com/dart-lang/vm_service_client/issues/17
|
||||||
|
Future<Null> enableIsolateStreams() async {
|
||||||
|
await connection.peer.sendRequest('streamListen', <String, String>{
|
||||||
|
'streamId': 'Isolate',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt to resume isolate if it was paused
|
// Attempt to resume isolate if it was paused
|
||||||
if (isolate.pauseEvent is VMPauseStartEvent) {
|
if (isolate.pauseEvent is VMPauseStartEvent) {
|
||||||
_log.trace('Isolate is paused at start.');
|
_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) {
|
|
||||||
return extension == _kFlutterExtensionMethod;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Tells the Dart VM Service to notify us about "Isolate" events.
|
|
||||||
///
|
|
||||||
/// This is a workaround for an issue in package:vm_service_client, which
|
|
||||||
/// subscribes to the "Isolate" stream lazily upon subscription, which
|
|
||||||
/// results in lost events.
|
|
||||||
///
|
|
||||||
/// Details: https://github.com/dart-lang/vm_service_client/issues/17
|
|
||||||
Future<Null> enableIsolateStreams() async {
|
|
||||||
await connection.peer.sendRequest('streamListen', <String, String>{
|
|
||||||
'streamId': 'Isolate',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the isolate is paused at the start, e.g. via the --start-paused
|
// 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
|
// option, then the VM service extension is not registered yet. Wait for
|
||||||
// it to be registered.
|
// it to be registered.
|
||||||
@ -269,8 +270,27 @@ class FlutterDriver {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point the service extension must be installed. Verify it.
|
// Invoked checkHealth and try to fix delays in the registration of Service
|
||||||
final Health health = await driver.checkHealth();
|
// extensions
|
||||||
|
Future<Health> checkHealth() async {
|
||||||
|
try {
|
||||||
|
// At this point the service extension must be installed. Verify it.
|
||||||
|
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) {
|
if (health.status != HealthStatus.ok) {
|
||||||
await client.close();
|
await client.close();
|
||||||
throw new DriverError('Flutter application health check failed.');
|
throw new DriverError('Flutter application health check failed.');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user