Unverified Commit 758b302c authored by Alexander Aprelev's avatar Alexander Aprelev Committed by GitHub

Add --preview-dart-2 relaunch test. (#15117)

* Add a test that measures/verifies start from warm state(app was previously compiled).

* Remove json file from the first run.
parent 85412d8b
...@@ -29,6 +29,8 @@ TaskFunction createHotModeTest({ bool isPreviewDart2: false }) { ...@@ -29,6 +29,8 @@ TaskFunction createHotModeTest({ bool isPreviewDart2: false }) {
options.add('--preview-dart-2'); options.add('--preview-dart-2');
setLocalEngineOptionIfNecessary(options); setLocalEngineOptionIfNecessary(options);
int hotReloadCount = 0; int hotReloadCount = 0;
Map<String, dynamic> twoReloadsData;
Map<String, dynamic> freshRestartReloadsData;
await inDirectory(flutterDirectory, () async { await inDirectory(flutterDirectory, () async {
rmTree(_editedFlutterGalleryDir); rmTree(_editedFlutterGalleryDir);
mkdirs(_editedFlutterGalleryDir); mkdirs(_editedFlutterGalleryDir);
...@@ -36,52 +38,100 @@ TaskFunction createHotModeTest({ bool isPreviewDart2: false }) { ...@@ -36,52 +38,100 @@ TaskFunction createHotModeTest({ bool isPreviewDart2: false }) {
await inDirectory(_editedFlutterGalleryDir, () async { await inDirectory(_editedFlutterGalleryDir, () async {
if (deviceOperatingSystem == DeviceOperatingSystem.ios) if (deviceOperatingSystem == DeviceOperatingSystem.ios)
await prepareProvisioningCertificates(_editedFlutterGalleryDir.path); await prepareProvisioningCertificates(_editedFlutterGalleryDir.path);
{
final Process process = await startProcess(
path.join(flutterDirectory.path, 'bin', 'flutter'),
<String>['run']..addAll(options),
environment: null
);
final Process process = await startProcess( final Completer<Null> stdoutDone = new Completer<Null>();
path.join(flutterDirectory.path, 'bin', 'flutter'), final Completer<Null> stderrDone = new Completer<Null>();
<String>['run']..addAll(options), process.stdout
environment: null .transform(UTF8.decoder)
); .transform(const LineSplitter())
.listen((String line) {
if (line.contains('\] Reloaded ')) {
if (hotReloadCount == 0) {
// Update the file and reload again.
final File appDartSource = file(path.join(
_editedFlutterGalleryDir.path, 'lib/gallery/app.dart'
));
appDartSource.writeAsStringSync(
appDartSource.readAsStringSync().replaceFirst(
"'Flutter Gallery'", "'Updated Flutter Gallery'"
)
);
process.stdin.writeln('r');
++hotReloadCount;
} else {
// Quit after second hot reload.
process.stdin.writeln('q');
}
}
print('stdout: $line');
}, onDone: () {
stdoutDone.complete();
});
process.stderr
.transform(UTF8.decoder)
.transform(const LineSplitter())
.listen((String line) {
print('stderr: $line');
}, onDone: () {
stderrDone.complete();
});
await Future.wait<Null>(
<Future<Null>>[stdoutDone.future, stderrDone.future]);
await process.exitCode;
final Completer<Null> stdoutDone = new Completer<Null>(); twoReloadsData = JSON.decode(benchmarkFile.readAsStringSync());
final Completer<Null> stderrDone = new Completer<Null>(); }
process.stdout benchmarkFile.deleteSync();
.transform(UTF8.decoder)
.transform(const LineSplitter()) // start `flutter run` again to make sure it loads from the previous state
.listen((String line) { // (in case of --preview-dart-2 frontend loads up from previously generated kernel files).
if (line.contains('\] Reloaded ')) { {
if (hotReloadCount == 0) { final Process process = await startProcess(
// Update the file and reload again. path.join(flutterDirectory.path, 'bin', 'flutter'),
final File appDartSource = file(path.join( <String>['run']..addAll(options),
_editedFlutterGalleryDir.path, 'lib/gallery/app.dart' environment: null
)); );
appDartSource.writeAsStringSync( final Completer<Null> stdoutDone = new Completer<Null>();
appDartSource.readAsStringSync().replaceFirst( final Completer<Null> stderrDone = new Completer<Null>();
"'Flutter Gallery'", "'Updated Flutter Gallery'" process.stdout
) .transform(UTF8.decoder)
); .transform(const LineSplitter())
process.stdin.writeln('r'); .listen((String line) {
++hotReloadCount; if (line.contains('\] Reloaded ')) {
} else {
// Quit after second hot reload.
process.stdin.writeln('q'); process.stdin.writeln('q');
} }
} print('stdout: $line');
print('stdout: $line'); }, onDone: () {
}, onDone: () { stdoutDone.complete(); }); stdoutDone.complete();
process.stderr });
.transform(UTF8.decoder) process.stderr
.transform(const LineSplitter()) .transform(UTF8.decoder)
.listen((String line) { .transform(const LineSplitter())
print('stderr: $line'); .listen((String line) {
}, onDone: () { stderrDone.complete(); }); print('stderr: $line');
}, onDone: () {
stderrDone.complete();
});
await Future.wait<Null>(
<Future<Null>>[stdoutDone.future, stderrDone.future]);
await process.exitCode;
await Future.wait<Null>(<Future<Null>>[stdoutDone.future, stderrDone.future]); freshRestartReloadsData =
return await process.exitCode; JSON.decode(benchmarkFile.readAsStringSync());
}
}); });
}); });
final Map<String, dynamic> twoReloadsData = JSON.decode(
benchmarkFile.readAsStringSync());
return new TaskResult.success( return new TaskResult.success(
<String, dynamic> { <String, dynamic> {
'hotReloadInitialDevFSSyncMilliseconds': twoReloadsData['hotReloadInitialDevFSSyncMilliseconds'][0], 'hotReloadInitialDevFSSyncMilliseconds': twoReloadsData['hotReloadInitialDevFSSyncMilliseconds'][0],
...@@ -93,6 +143,7 @@ TaskFunction createHotModeTest({ bool isPreviewDart2: false }) { ...@@ -93,6 +143,7 @@ TaskFunction createHotModeTest({ bool isPreviewDart2: false }) {
'hotReloadDevFSSyncMillisecondsAfterChange': twoReloadsData['hotReloadDevFSSyncMilliseconds'][1], 'hotReloadDevFSSyncMillisecondsAfterChange': twoReloadsData['hotReloadDevFSSyncMilliseconds'][1],
'hotReloadFlutterReassembleMillisecondsAfterChange': twoReloadsData['hotReloadFlutterReassembleMilliseconds'][1], 'hotReloadFlutterReassembleMillisecondsAfterChange': twoReloadsData['hotReloadFlutterReassembleMilliseconds'][1],
'hotReloadVMReloadMillisecondsAfterChange': twoReloadsData['hotReloadVMReloadMilliseconds'][1], 'hotReloadVMReloadMillisecondsAfterChange': twoReloadsData['hotReloadVMReloadMilliseconds'][1],
'hotReloadInitialDevFSSyncAfterRelaunchMilliseconds' : freshRestartReloadsData['hotReloadInitialDevFSSyncMilliseconds'][0],
}, },
benchmarkScoreKeys: <String>[ benchmarkScoreKeys: <String>[
'hotReloadInitialDevFSSyncMilliseconds', 'hotReloadInitialDevFSSyncMilliseconds',
...@@ -104,6 +155,7 @@ TaskFunction createHotModeTest({ bool isPreviewDart2: false }) { ...@@ -104,6 +155,7 @@ TaskFunction createHotModeTest({ bool isPreviewDart2: false }) {
'hotReloadDevFSSyncMillisecondsAfterChange', 'hotReloadDevFSSyncMillisecondsAfterChange',
'hotReloadFlutterReassembleMillisecondsAfterChange', 'hotReloadFlutterReassembleMillisecondsAfterChange',
'hotReloadVMReloadMillisecondsAfterChange', 'hotReloadVMReloadMillisecondsAfterChange',
'hotReloadInitialDevFSSyncAfterRelaunchMilliseconds',
] ]
); );
}; };
......
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