Commit 937b98e1 authored by Carlo Bernaschina's avatar Carlo Bernaschina Committed by GitHub

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.
parent 79d08f68
......@@ -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,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
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) {
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
// option, then the VM service extension is not registered yet. Wait for
// it to be registered.
......@@ -269,8 +270,27 @@ class FlutterDriver {
);
}
// At this point the service extension must be installed. Verify it.
final Health health = await driver.checkHealth();
// 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.
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.');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment