Fix flakiness in hot_reload_test.dart (#158271)

The test was immediately checking the contents of stdout after the daemon indicated that the hot reload had completed. This could cause a race since the reloaded code may not have had time to execute.

Fixes https://github.com/flutter/flutter/issues/158245
This commit is contained in:
Ben Konyi
2024-11-06 17:14:19 -05:00
committed by GitHub
parent b8e56e3063
commit 933323488b

View File

@@ -69,11 +69,21 @@ void main() {
testWithoutContext('newly added code executes during hot reload', () async {
final StringBuffer stdout = StringBuffer();
final StreamSubscription<String> subscription = flutter.stdout.listen(stdout.writeln);
final Completer<void> completer = Completer<void>();
final StreamSubscription<String> subscription = flutter.stdout.listen((String e) {
stdout.writeln(e);
// If hot reload properly executes newly added code, the 'RELOAD WORKED' message should
// be printed before 'TICK 2'. If we don't wait for some signal that the build method
// has executed after the reload, this test can encounter a race.
if (e.contains('((((TICK 2))))')) {
completer.complete();
}
});
await flutter.run();
project.uncommentHotReloadPrint();
try {
await flutter.hotReload();
await completer.future;
expect(stdout.toString(), contains('(((((RELOAD WORKED)))))'));
} finally {
await subscription.cancel();