Repository: flutter
Issue: WidgetTester.pump inconsistently flushes microtasks
Labels: a: tests,framework,dependency: dart,has reproducible steps,P2,found in release: 3.10,found in release: 3.11,team-framework,triaged-framework

## Steps to Reproduce

Flutter widget test:

```dart
  testWidgets('async StreamController add() inconsistently executed', (WidgetTester tester) async {
    final source = StreamController<String>();
    var index = 0;
    await tester.pumpWidget(MaterialApp(
      home: StreamBuilder(
        stream: source.stream,
        builder: (context, snapshot) {
          index += 1;
          return Text('$index');
        },
      ),
    ));
    expect(find.text('1'), findsOneWidget);

    source.add('Hello');
    await tester.pump();
    expect(find.text('2'), findsOneWidget);

    // The below three lines are almost identical to the above,
    // except for the text changing to 'Bye' and '3' (next index).
    source.add('Bye');
    await tester.pump();
    expect(find.text('3'), findsOneWidget);
    // Yet this expect crashes:
    //  Expected: exactly one matching node in the widget tree
    //  Actual: _TextFinder:<zero widgets with text "3" (ignoring offstage widgets)>
    //   Which: means none were found but one was expected
  });
```

**Expected results:** either expect `find.text('2')` crashes as well, or none of them do.

**Actual results:** only the last expect crashes.

If I insert `await null;` before `await tester.pump()`, the test passes.
If I add Duration parameter to `tester.pump()`, the test passes.

I believe the problem may be in microtask flushing code, somewhere around
https://github.com/flutter/flutter/blob/25a557d49e7f834ce36f2c16fd1a6c14cc485b9f/packages/flutter_test/lib/src/binding.dart#L968-L972

And thus _there's a chance_ it's related to #40074.

<details>
  <summary>flutter doctor -v</summary>

```
[✓] Flutter (Channel stable, 2.0.3, on Linux, locale en_US.UTF-8)
    • Flutter version 2.0.3 at /home/artem/pkg/flutter
    • Framework revision 4d7946a68d (2 weeks ago), 2021-03-18 17:24:33 -0700
    • Engine revision 3459eb2436
    • Dart version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /home/artem/Android/Sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /home/artem/Android/Sdk
    • ANDROID_SDK_ROOT = /home/artem/Android/Sdk
    • Java binary at: /opt/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio
    • Android Studio at /opt/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (1 available)
    • Google Pixel Slate (mobile) • emulator-5554 • android-x64 • Android 9 (API 28)

! Doctor found issues in 1 category.
```

</details>