Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter_android] Fix timeouts in the integration tests #6857

Merged
merged 3 commits into from
Dec 16, 2022

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Dec 16, 2022

Fixes timeouts caused by a race condition when loading a page. In pre-4.0 webview_flutter, the widget was passed the initial url, so we were able to call await pageLoads.stream.first; before the page was loaded.

However, these tests would load the url before we could call await pageLoads.stream.first;, leading to a timeout.

This could also be responsible for the test crashes, but I'll keep an eye on the CI to make sure.

Edit: Tests passed first time, so this could be the only fixed needed!

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 relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • 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.

@github-actions github-actions bot added p: webview_flutter Edits files for a webview_flutter plugin platform-android labels Dec 16, 2022
@bparrishMines bparrishMines changed the title fix timeouts [webview_flutter_android] Fix timeouts in the integration tests Dec 16, 2022
@stuartmorgan
Copy link
Contributor

Can you elaborate on what the race is exactly? The PR mentions pageLoads.stream.first and loading the URL, but those operations are still being done in the same order. Is it a problem with setOnPageFinished ordering?

@bparrishMines
Copy link
Contributor Author

bparrishMines commented Dec 16, 2022

I tried to find a clever solution, but ultimately just gave up.

The problem is that these tests are using StreamController<String>.broadcast(); which doesn't buffer values. So if a url loads before we get to the line await pageLoads.stream.first, the test timeouts.

My initial solution in 1d8ee9c just moved the loadRequest closer to the call of await pageLoads.stream.first which is admittedly a subpar solution.

My second solution in c3458ac removed the broadcast() constructor, but you can't listen to a non-broadcast stream more than once. (throws an error)

Finally, I just gave up and switched to completers.

Edit: StreamController<String>(); does buffer values.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

Ah, I missed that they were broadcast streams. Thanks for the explanation, LGTM!

@stuartmorgan
Copy link
Contributor

Looks like the iOS package and the app-facing package have the same test structure, so we should be sure those get updated as well.

@bparrishMines bparrishMines added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 16, 2022
@auto-submit auto-submit bot merged commit fd2841f into flutter:main Dec 16, 2022
@bparrishMines bparrishMines deleted the webview_android_flake branch December 16, 2022 19:55
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2022
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Dec 19, 2022
* 5f62d21eb [local_auth] Fix failed biometric authentication not throwing error (flutter/plugins#6821)

* ca974ab0c [webview_flutter_web] Copies web implementation of webview_flutter from v4_webview (flutter/plugins#6854)

* 4d11be416 [image_picker] Don't store null paths in lost cache (flutter/plugins#6678)

* fd2841fd0 [webview_flutter_android] Fix timeouts in the integration tests (flutter/plugins#6857)

* abc9f9a9b [flutter_plugin_tools] If `clang-format` does not run, fall back to other executables in PATH (flutter/plugins#6853)

* 7efb5e89d [video_player] Add compatibility with the current platform interface (flutter/plugins#6855)

* 32dcbf3e3 [image_picker] Improve image_picker for iOS to handle more image types (flutter/plugins#6812)

* 840a04954 [webview_flutter] Copies app-facing implementation of webview_flutter from v4_webview (flutter/plugins#6856)
gspencergoog pushed a commit to gspencergoog/flutter that referenced this pull request Jan 19, 2023
…#117314)

* 5f62d21eb [local_auth] Fix failed biometric authentication not throwing error (flutter/plugins#6821)

* ca974ab0c [webview_flutter_web] Copies web implementation of webview_flutter from v4_webview (flutter/plugins#6854)

* 4d11be416 [image_picker] Don't store null paths in lost cache (flutter/plugins#6678)

* fd2841fd0 [webview_flutter_android] Fix timeouts in the integration tests (flutter/plugins#6857)

* abc9f9a9b [flutter_plugin_tools] If `clang-format` does not run, fall back to other executables in PATH (flutter/plugins#6853)

* 7efb5e89d [video_player] Add compatibility with the current platform interface (flutter/plugins#6855)

* 32dcbf3e3 [image_picker] Improve image_picker for iOS to handle more image types (flutter/plugins#6812)

* 840a04954 [webview_flutter] Copies app-facing implementation of webview_flutter from v4_webview (flutter/plugins#6856)
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
…ter#6857)

* fix timeouts

* remove broadcast instead

* just use completers like a lame person
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: webview_flutter Edits files for a webview_flutter plugin platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants