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 1108c032cf434..ca2d13b7fc5de 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();