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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user