Skip to content

Export elapseBlocking to test binding, so slow sync work can be simulated such as a slow widget build#112619

Merged
auto-submit[bot] merged 5 commits intoflutter:masterfrom
fzyzcjy:feat/elapse-blocking
Oct 5, 2022
Merged

Export elapseBlocking to test binding, so slow sync work can be simulated such as a slow widget build#112619
auto-submit[bot] merged 5 commits intoflutter:masterfrom
fzyzcjy:feat/elapse-blocking

Conversation

@fzyzcjy
Copy link
Contributor

@fzyzcjy fzyzcjy commented Sep 29, 2022

There are needs to simulate sync heavy work, such as a slow widget build, in flutter widget tests. This method simply expose that.

As a remark, this cannot be replaced by runAsync. Consider the following example:

    testWidgets('can use to simulate slow build', (WidgetTester tester) async {
      final DateTime beforeTime = binding.clock.now();

      await tester.pumpWidget(Builder(builder: (_) {
        bool timerCalled = false;
        Timer.run(() => timerCalled = true);

        binding.elapseBlocking(const Duration(seconds: 1));

        // if we use `delayed` instead of `elapseBlocking`, such as
        // binding.delayed(const Duration(seconds: 1));
        // the timer will be called here. Surely, that violates how
        // a flutter widget build works
        expect(timerCalled, false);

        return Container();
      }));

      expect(binding.clock.now(), beforeTime.add(const Duration(seconds: 1)));
      binding.idle();
    });

As is discussed in the comments in the example, if we use delayed, timers will be fired when executing half of a build function, which is totally wrong.

List which issues are fixed by this PR. You must list at least one issue.
Close #112620

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Sep 29, 2022
Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@pdblasi-google pdblasi-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pdblasi-google pdblasi-google added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 5, 2022
@auto-submit auto-submit bot merged commit c7b40a5 into flutter:master Oct 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Oct 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Oct 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export elapseBlocking to test binding, so slow sync work can be simulated such as a slow widget build

3 participants