Skip to content

Commit 9333234

Browse files
authored
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 flutter/flutter#158245
1 parent b8e56e3 commit 9333234

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/flutter_tools/test/integration.shard/hot_reload_test.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,21 @@ void main() {
6969

7070
testWithoutContext('newly added code executes during hot reload', () async {
7171
final StringBuffer stdout = StringBuffer();
72-
final StreamSubscription<String> subscription = flutter.stdout.listen(stdout.writeln);
72+
final Completer<void> completer = Completer<void>();
73+
final StreamSubscription<String> subscription = flutter.stdout.listen((String e) {
74+
stdout.writeln(e);
75+
// If hot reload properly executes newly added code, the 'RELOAD WORKED' message should
76+
// be printed before 'TICK 2'. If we don't wait for some signal that the build method
77+
// has executed after the reload, this test can encounter a race.
78+
if (e.contains('((((TICK 2))))')) {
79+
completer.complete();
80+
}
81+
});
7382
await flutter.run();
7483
project.uncommentHotReloadPrint();
7584
try {
7685
await flutter.hotReload();
86+
await completer.future;
7787
expect(stdout.toString(), contains('(((((RELOAD WORKED)))))'));
7888
} finally {
7989
await subscription.cancel();

0 commit comments

Comments
 (0)