From dfbbfcd39099d0251666ae10b3f145f22d283b10 Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Thu, 7 Nov 2019 13:01:32 -0800 Subject: [PATCH] Fixing local golden output flake (#44307) --- .../flutter_goldens/lib/flutter_goldens.dart | 9 ++++---- .../test/flutter_goldens_test.dart | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/flutter_goldens/lib/flutter_goldens.dart b/packages/flutter_goldens/lib/flutter_goldens.dart index 3b7463a8826..c5bf8a09bf3 100644 --- a/packages/flutter_goldens/lib/flutter_goldens.dart +++ b/packages/flutter_goldens/lib/flutter_goldens.dart @@ -506,10 +506,11 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC } failureDiffs[expectation] = result; } - failureDiffs.forEach((String expectation, ComparisonResult result) async { - if (await skiaClient.isValidDigestForExpectation(expectation, golden.path)) - generateFailureOutput(result, golden, basedir, key: expectation); - }); + + for (MapEntry entry in failureDiffs.entries) { + if (await skiaClient.isValidDigestForExpectation(entry.key, golden.path)) + generateFailureOutput(entry.value, golden, basedir, key: entry.key); + } return false; } } diff --git a/packages/flutter_goldens/test/flutter_goldens_test.dart b/packages/flutter_goldens/test/flutter_goldens_test.dart index ceec993712f..6269d94aeb2 100644 --- a/packages/flutter_goldens/test/flutter_goldens_test.dart +++ b/packages/flutter_goldens/test/flutter_goldens_test.dart @@ -741,6 +741,27 @@ void main() { isTrue, ); }); + + test('compare properly awaits validation & output before failing.', () async { + final Completer completer = Completer(); + when(mockSkiaClient.isValidDigestForExpectation( + '55109a4bed52acc780530f7a9aeff6c0', + 'library.flutter.golden_test.1.png', + )) + .thenAnswer((_) => completer.future); + final Future result = comparator.compare( + Uint8List.fromList(_kFailPngBytes), + Uri.parse('flutter.golden_test.1.png'), + ); + bool shouldThrow = true; + result.then((_) { + if (shouldThrow) + fail('Compare completed before validation completed!'); + }); + await Future.value(); + shouldThrow = false; + completer.complete(Future.value(false)); + }); }); }); }