From 933323488b6f7820ca62ba4203c3d00d14076c23 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Wed, 6 Nov 2024 17:14:19 -0500 Subject: [PATCH] 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 --- .../test/integration.shard/hot_reload_test.dart | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/test/integration.shard/hot_reload_test.dart b/packages/flutter_tools/test/integration.shard/hot_reload_test.dart index 1108c032cf..ca2d13b7fc 100644 --- a/packages/flutter_tools/test/integration.shard/hot_reload_test.dart +++ b/packages/flutter_tools/test/integration.shard/hot_reload_test.dart @@ -69,11 +69,21 @@ void main() { testWithoutContext('newly added code executes during hot reload', () async { final StringBuffer stdout = StringBuffer(); - final StreamSubscription subscription = flutter.stdout.listen(stdout.writeln); + final Completer completer = Completer(); + final StreamSubscription 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();