Skip to content

Animation controller test - #88251

Merged
gspencergoog merged 3 commits into
flutter:masterfrom
Swiftaxe:animation_controller_test
Aug 16, 2021
Merged

gspencergoog merged 3 commits into
flutter:masterfrom
Swiftaxe:animation_controller_test

Conversation

@Swiftaxe

Copy link
Copy Markdown
Contributor

Fixes test/animation/animation_controller_test.dart in #85160

Problem:
The test 'animateTo can deal with duration == Duration.Zero' was failing with the following error:

Expected: <0>
Actual: <5>
Expected no animation.
package:test_api expect
package:flutter_test/src/widget_tester.dart 484:3 expect
test/animation/animation_controller_test.dart 511:5 main.

Following line finds 5 transientCallbacks scheduled, while expecting zero, if shuffled with seed 123:

expect(SchedulerBinding.instance!.transientCallbackCount, equals(0), reason: 'Expected no animation.');

This is caused by some other test leaving transientCallbacks scheduled.

The tests I have identified leaving transientCallbacks behind is:
1. 'calling repeat with reverse set to true makes the animation alternate 'between lowerBound and upperBound values on each repeat' (1 callback)
2. calling repeat with specified min and max values makes the animation alternate between min and max values on each repeat (1 callback)
3. 2 AnimationBehavior > AnimationBehavior.normal runs "faster" than AnimationBehavior.preserve (2 callbacks)
4. 1 Simulations run forward (1 callback)
5. 1 Simulations run forward even after a reverse run (1 callback)
6. 1 Repeating animation with reverse: true report as forward and reverse (1 callback)

Fix:
By disposing the AnimationController after each test, the transientCallbacks get cleaned up.
I chose to dispose all controllers in every test, to make sure there is no risk of leaks.

Alternate fixes:

  • I tried disposing the controller variable for all tests in tearDown instead of inside each test, but that broke some other tests due to controllers being disposed twice.
  • One could consider to only dispose the controllers confirmed to break the test 'animateTocan deal with…'.

I am happy for any feedback about the best solution.

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 feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard Bot added the framework flutter/packages/flutter repository. See also f: labels. label Aug 15, 2021
@google-cla

google-cla Bot commented Aug 15, 2021

Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@google-cla google-cla Bot added the cla: no label Aug 15, 2021
@Swiftaxe

Copy link
Copy Markdown
Contributor Author

@googlebot I fixed it.

@google-cla

google-cla Bot commented Aug 15, 2021

Copy link
Copy Markdown

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@SigmaAD

SigmaAD commented Aug 15, 2021

Copy link
Copy Markdown

@googlebot I consent.

@google-cla google-cla Bot added cla: yes and removed cla: no labels Aug 15, 2021

@gspencergoog gspencergoog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

This is great, thanks!

@gspencergoog
gspencergoog merged commit fe337dc into flutter:master Aug 16, 2021
blasten pushed a commit to blasten/flutter that referenced this pull request Aug 19, 2021
Co-authored-by: Alexander Dahlberg <[email protected]>

Fixes test/animation/animation_controller_test.dart in flutter#85160

Problem:
The test 'animateTo can deal with duration == Duration.Zero' was failing with the following error:

Expected: <0>
Actual: <5>
Expected no animation.
package:test_api expect
package:flutter_test/src/widget_tester.dart 484:3 expect
test/animation/animation_controller_test.dart 511:5 main.

Following line finds 5 transientCallbacks scheduled, while expecting zero, if shuffled with seed 123:

expect(SchedulerBinding.instance!.transientCallbackCount, equals(0), reason: 'Expected no animation.');

This is caused by some other test leaving transientCallbacks scheduled.

Fix:
By disposing the AnimationController after each test, the transientCallbacks get cleaned up.
I chose to dispose all controllers in every test, to make sure there is no risk of leaks.
@Swiftaxe
Swiftaxe deleted the animation_controller_test branch August 23, 2021 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants