Commit c72381aa authored by Devon Carew's avatar Devon Carew Committed by GitHub

refactor commands_test to choose a free port for the service protocol (#11446)

* refactor commands_test to choose a free port for the service protocol

* discover the service protocol port

* add a todo
parent c80d2482
...@@ -13,10 +13,13 @@ import 'package:flutter_devicelab/framework/adb.dart'; ...@@ -13,10 +13,13 @@ import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/utils.dart'; import 'package:flutter_devicelab/framework/utils.dart';
const int kObservatoryPort = 8888; // "An Observatory debugger and profiler on iPhone SE is available at: http://127.0.0.1:8100/"
final RegExp observatoryRegExp = new RegExp(r'An Observatory debugger .* is available at: (\S+:(\d+))');
void main() { void main() {
task(() async { task(() async {
int vmServicePort;
final Device device = await devices.workingDevice; final Device device = await devices.workingDevice;
await device.unlock(); await device.unlock();
final Directory appDir = dir(path.join(flutterDirectory.path, 'dev/integration_tests/ui')); final Directory appDir = dir(path.join(flutterDirectory.path, 'dev/integration_tests/ui'));
...@@ -26,7 +29,7 @@ void main() { ...@@ -26,7 +29,7 @@ void main() {
print('run: starting...'); print('run: starting...');
final Process run = await startProcess( final Process run = await startProcess(
path.join(flutterDirectory.path, 'bin', 'flutter'), path.join(flutterDirectory.path, 'bin', 'flutter'),
<String>['run', '--verbose', '--observatory-port=$kObservatoryPort', '-d', device.deviceId, 'lib/commands.dart'], <String>['run', '--verbose', '-d', device.deviceId, 'lib/commands.dart'],
); );
final StreamController<String> stdout = new StreamController<String>.broadcast(); final StreamController<String> stdout = new StreamController<String>.broadcast();
run.stdout run.stdout
...@@ -35,7 +38,10 @@ void main() { ...@@ -35,7 +38,10 @@ void main() {
.listen((String line) { .listen((String line) {
print('run:stdout: $line'); print('run:stdout: $line');
stdout.add(line); stdout.add(line);
if (line.contains(new RegExp(r'^\[\s+\] For a more detailed help message, press "h"\. To quit, press "q"\.'))) { if (line.contains(observatoryRegExp)) {
final Match match = observatoryRegExp.firstMatch(line);
vmServicePort = int.parse(match.group(2));
print('service protocol connection available at ${match.group(1)}');
print('run: ready!'); print('run: ready!');
ready.complete(); ready.complete();
ok ??= true; ok ??= true;
...@@ -52,33 +58,35 @@ void main() { ...@@ -52,33 +58,35 @@ void main() {
if (!ok) if (!ok)
throw 'Failed to run test app.'; throw 'Failed to run test app.';
final VMServiceClient client = new VMServiceClient.connect('ws://localhost:$kObservatoryPort/ws'); final VMServiceClient client = new VMServiceClient.connect('ws://localhost:$vmServicePort/ws');
final DriveHelper driver = new DriveHelper(vmServicePort);
await drive('none'); await driver.drive('none');
print('test: pressing "p" to enable debugPaintSize...'); print('test: pressing "p" to enable debugPaintSize...');
run.stdin.write('p'); run.stdin.write('p');
await drive('debug_paint'); await driver.drive('debug_paint');
print('test: pressing "p" again...'); print('test: pressing "p" again...');
run.stdin.write('p'); run.stdin.write('p');
await drive('none'); await driver.drive('none');
print('test: pressing "P" to enable performance overlay...'); print('test: pressing "P" to enable performance overlay...');
run.stdin.write('P'); run.stdin.write('P');
await drive('performance_overlay'); await driver.drive('performance_overlay');
print('test: pressing "P" again...'); print('test: pressing "P" again...');
run.stdin.write('P'); run.stdin.write('P');
await 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...'));
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 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...'));
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 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;
if (result != 0) if (result != 0)
...@@ -90,26 +98,32 @@ void main() { ...@@ -90,26 +98,32 @@ void main() {
}); });
} }
Future<Null> drive(String name) async { class DriveHelper {
print('drive: running commands_$name check...'); DriveHelper(this.vmServicePort);
final Process drive = await startProcess(
path.join(flutterDirectory.path, 'bin', 'flutter'), final int vmServicePort;
<String>['drive', '--use-existing-app', 'http://127.0.0.1:$kObservatoryPort/', '--keep-app-running', '--driver', 'test_driver/commands_${name}_test.dart'],
); Future<Null> drive(String name) async {
drive.stdout print('drive: running commands_$name check...');
.transform(UTF8.decoder) final Process drive = await startProcess(
.transform(const LineSplitter()) path.join(flutterDirectory.path, 'bin', 'flutter'),
.listen((String line) { <String>['drive', '--use-existing-app', 'http://127.0.0.1:$vmServicePort/', '--keep-app-running', '--driver', 'test_driver/commands_${name}_test.dart'],
);
drive.stdout
.transform(UTF8.decoder)
.transform(const LineSplitter())
.listen((String line) {
print('drive:stdout: $line'); print('drive:stdout: $line');
}); });
drive.stderr drive.stderr
.transform(UTF8.decoder) .transform(UTF8.decoder)
.transform(const LineSplitter()) .transform(const LineSplitter())
.listen((String line) { .listen((String line) {
stderr.writeln('drive:stderr: $line'); stderr.writeln('drive:stderr: $line');
}); });
final int result = await drive.exitCode; final int result = await drive.exitCode;
if (result != 0) if (result != 0)
throw 'Failed to drive test app (exit code $result).'; throw 'Failed to drive test app (exit code $result).';
print('drive: finished commands_$name check successfully.'); print('drive: finished commands_$name check successfully.');
}
} }
...@@ -30,6 +30,8 @@ void main() { ...@@ -30,6 +30,8 @@ void main() {
final Completer<Null> ready = new Completer<Null>(); final Completer<Null> ready = new Completer<Null>();
bool ok; bool ok;
print('run: starting...'); print('run: starting...');
// TODO(devoncarew): Instead of passing in a specific port, we should let the app
// bind to a free port and detect which port was chosen; see commands_test.dart.
final Process run = await startProcess( final Process run = await startProcess(
path.join(flutterDirectory.path, 'bin', 'flutter'), path.join(flutterDirectory.path, 'bin', 'flutter'),
<String>['run', '--verbose', '--observatory-port=8888', '-d', device.deviceId, '--route', '/smuggle-it', 'lib/route.dart'], <String>['run', '--verbose', '--observatory-port=8888', '-d', device.deviceId, '--route', '/smuggle-it', 'lib/route.dart'],
......
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