Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be clearer about when and why we override HttpClient in tests #49844

Merged
merged 4 commits into from
Jan 31, 2020

Conversation

dnfield
Copy link
Contributor

@dnfield dnfield commented Jan 30, 2020

Description

Outside of browser contexts, we override the HttpClient implementation to one that always returns 400 - this helps make tests more hermetic and prevent users from making mistakes in tests by introduce real life network calls into a unit test.

This can be confusing for users, particularly if they're mixing both testWidgets and test tests in the same suite, and it's unclear that the binding has taken over the whole suite. This adds new functionality to print out a warning message if a failing test has created our special HttpClient, and updates docs on the TestFlutterWidgetsBinding class.

Related Issues

fixes #35318

Tests

I added the following tests:

Test that checks that we print out the message, and that we only do it once per suite.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

@fluttergithubbot fluttergithubbot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Jan 30, 2020
@override
HttpClient createHttpClient(SecurityContext _) {
if (!warningPrinted) {
Copy link
Member

Choose a reason for hiding this comment

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

This would output the message for any widget test which incidentally built a network image. It doesn't seem desirable if their test was otherwise working.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there some way to just do this on a test failure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could try to use test_package.printOnFailure, but I'm not sure how to test that anymore - hah

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I can put it in a new test file and run it under a harness that asserts the test fails and greps the message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok - now it should only print the warning if a test fails and the HttpClient was created.

Copy link
Member

@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 if LG to everyone else

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

LGTM!

@dnfield dnfield merged commit b2a27c1 into flutter:master Jan 31, 2020
@dnfield dnfield deleted the http_error_test branch January 31, 2020 17:22
@fluttergithubbot fluttergithubbot added the team Infra upgrades, team productivity, code health, technical debt. See also team: labels. label Jan 31, 2020
@fluttergithubbot
Copy link
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@dnfield
Copy link
Contributor Author

dnfield commented Jan 31, 2020

The bot fell asleep on the job!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Widget tests overriding HTTP to return 400 is incredibly confusing and unintuitive
5 participants