From b94b58429863f7ee1d82f2921c0ed548d58b6813 Mon Sep 17 00:00:00 2001 From: Camille Simon <43054281+camsim99@users.noreply.github.com> Date: Tue, 4 Oct 2022 12:05:39 -0700 Subject: [PATCH] [Android] Fix spell_check integration test flakiness (#112109) --- .ci.yaml | 2 +- .../integration_test/integration_test.dart | 53 ++++++++++++------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/.ci.yaml b/.ci.yaml index 07bfb46c97..ce777a7a4a 100644 --- a/.ci.yaml +++ b/.ci.yaml @@ -2107,7 +2107,7 @@ targets: task_name: routing_test - name: Linux_android spell_check_test - bringup: true + bringup: true # TESTING PURPOSES ONLY recipe: devicelab/devicelab_drone presubmit: false timeout: 60 diff --git a/dev/integration_tests/spell_check/integration_test/integration_test.dart b/dev/integration_tests/spell_check/integration_test/integration_test.dart index 088416c45c..4250dd8ea8 100644 --- a/dev/integration_tests/spell_check/integration_test/integration_test.dart +++ b/dev/integration_tests/spell_check/integration_test/integration_test.dart @@ -12,22 +12,35 @@ import 'package:spell_check/main.dart'; late DefaultSpellCheckService defaultSpellCheckService; late Locale locale; -/// Copy from flutter/test/widgets/editable_text_utils.dart. -RenderEditable findRenderEditable(WidgetTester tester, Type type) { - final RenderObject root = tester.renderObject(find.byType(type)); +/// Waits to find [EditableText] that displays text with misspelled +/// words marked the same as the [TextSpan] provided and returns +/// true if it is found before timing out at 20 seconds. +Future findTextSpanTree( + WidgetTester tester, + TextSpan inlineSpan, +) async { + final RenderObject root = tester.renderObject(find.byType(EditableText)); expect(root, isNotNull); - late RenderEditable renderEditable; + RenderEditable? renderEditable; void recursiveFinder(RenderObject child) { - if (child is RenderEditable) { + if (child is RenderEditable && child.text == inlineSpan) { renderEditable = child; return; } child.visitChildren(recursiveFinder); } - root.visitChildren(recursiveFinder); - expect(renderEditable, isNotNull); - return renderEditable; + + final DateTime endTime = tester.binding.clock.now().add(const Duration(seconds: 20)); + do { + if (tester.binding.clock.now().isAfter(endTime)) { + return false; + } + await tester.pump(const Duration(seconds: 1)); + root.visitChildren(recursiveFinder); + } while (renderEditable == null); + + return true; } Future main() async { @@ -147,21 +160,21 @@ Future main() async { await tester.pumpWidget(const MyApp()); - await tester.enterText(find.byType(EditableText), 'Hey cfabiueqqocnakoef! Hey!'); - await tester.pumpAndSettle(); - - final RenderEditable renderEditable = findRenderEditable(tester, EditableText); - final TextSpan textSpanTree = renderEditable.text! as TextSpan; + await tester.enterText(find.byType(EditableText), 'Hey cfabiueq qocnakoef! Hey!'); const TextSpan expectedTextSpanTree = TextSpan( - style: style, - children: [ - TextSpan(style: style, text: 'Hey '), - TextSpan(style: misspelledTextStyle, text: 'cfabiueqqocnakoef'), - TextSpan(style: style, text: '! Hey!'), - ]); + style: style, + children: [ + TextSpan(style: style, text: 'Hey '), + TextSpan(style: misspelledTextStyle, text: 'cfabiueq'), + TextSpan(style: style, text: ' '), + TextSpan(style: misspelledTextStyle, text: 'qocnakoef'), + TextSpan(style: style, text: '! Hey!'), + ]); - expect(textSpanTree, equals(expectedTextSpanTree)); + final bool expectedTextSpanTreeFound = await findTextSpanTree(tester, expectedTextSpanTree); + + expect(expectedTextSpanTreeFound, isTrue); }); test(