Skip to content

[Widget Preview] Fix flaky integration test timeout during flutter clean#184991

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
bkonyi:fix_widget_preview_smoke_test_flake
Apr 16, 2026
Merged

[Widget Preview] Fix flaky integration test timeout during flutter clean#184991
auto-submit[bot] merged 7 commits into
flutter:masterfrom
bkonyi:fix_widget_preview_smoke_test_flake

Conversation

@bkonyi

@bkonyi bkonyi commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

The test was flaking and timing out because it requested a Hot Restart via DTD immediately after running flutter clean on the root project. Wiping the root project's .dart_tool/ directory deletes package_config.json, which breaks the background Analysis Server and incremental compilers. Because the compiler cannot re-resolve dependencies, the Hot Restart fails and the previewer never sends the second Connected event, resulting in a timeout.

This fix resolves the flakiness by synchronously restoring dependencies using flutter pub get right after the flutter clean call. This restores package_config.json so the background compilers and Analysis Server can successfully re-read dependencies and execute the Hot Restart deterministically. We also updated process spawners to use addTearDown logic to ensure leaked processes are safely killed after test completion.

Fixes #184985

@bkonyi bkonyi requested a review from loic-sharma April 13, 2026 19:32
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 13, 2026
@bkonyi bkonyi force-pushed the fix_widget_preview_smoke_test_flake branch from 7322ee4 to 23298fa Compare April 13, 2026 19:33
@bkonyi bkonyi added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Apr 13, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request adds a .gitignore for the widget preview scaffold integration test, ensures the widget preview process is cleaned up and dependencies are restored during smoke tests, and adds validation to detect unexpected process exits. The review feedback suggests using the --offline flag for pub get to prevent CI flakiness, racing the connection completer against process exit for clearer failure messages, and awaiting the process exit code during teardown to ensure resource release.

Comment thread packages/flutter_tools/test/integration.shard/widget_preview_smoke_test.dart Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 13, 2026
loic-sharma
loic-sharma previously approved these changes Apr 13, 2026

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for fixing this so quickly!

@auto-submit

auto-submit Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/184991, Failed to enqueue flutter/flutter/184991 with HTTP 400: Pull request Required status check "Merge Queue Guard" is expected..

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 13, 2026
@bkonyi bkonyi added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Apr 13, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 13, 2026
@auto-submit

auto-submit Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/184991, because - The status or check suite Windows tool_integration_tests_10_10 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@loic-sharma

loic-sharma commented Apr 13, 2026

Copy link
Copy Markdown
Member

Hm looks like this change caused some failures: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8684608000406265473/+/u/run_test.dart_for_tool_integration_tests_shard_and_subshard_10_10/stdout

Exception...
07:39 +15 ~1: test/integration.shard/widget_preview_detection_test.dart: widget-preview detection Removed previews are detected (LSP)
Bad state: Cannot add new events after calling close
#0      _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:256:24)
#1      startWidgetPreview.<anonymous closure> (file:///C:/b/s/w/ir/x/w/flutter/packages/flutter_tools/test/integration.shard/widget_preview_test_helpers.dart:69:16)
#2      _rootRunUnary (dart:async/zone_root.dart:48:47)
#3      _CustomZone.runUnary (dart:async/zone.dart:733:19)
#4      _CustomZone.runUnaryGuarded (dart:async/zone.dart:633:7)
#5      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#6      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#7      _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:67:11)
#8      _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
#9      _StringAdapterSink.add (dart:convert/string_conversion.dart:231:11)
#10     _LineSplitterSink._addLines (dart:convert/line_splitter.dart:164:13)
#11     _LineSplitterSink.addSlice (dart:convert/line_splitter.dart:131:7)
#12     StringConversionSink.add (dart:convert/string_conversion.dart:40:5)
#13     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:115:24)
#14     _rootRunUnary (dart:async/zone_root.dart:48:47)
#15     _CustomZone.runUnary (dart:async/zone.dart:733:19)
#16     _CustomZone.runUnaryGuarded (dart:async/zone.dart:633:7)
#17     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#18     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#19     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:67:11)
#20     _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
#21     _StringAdapterSink.add (dart:convert/string_conversion.dart:231:11)
#22     _StringAdapterSink.addSlice (dart:convert/string_conversion.dart:236:7)
#23     _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:316:20)
#24     _Utf8ConversionSink.add (dart:convert/string_conversion.dart:309:5)
#25     _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:70:18)
#26     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:115:24)
#27     _rootRunUnary (dart:async/zone_root.dart:48:47)
#28     _CustomZone.runUnary (dart:async/zone.dart:733:19)
#29     _CustomZone.runUnaryGuarded (dart:async/zone.dart:633:7)
#30     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#31     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#32     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
#33     _StreamController._add (dart:async/stream_controller.dart:663:7)
#34     _StreamController.add (dart:async/stream_controller.dart:618:5)
#35     _Socket._onData (dart:io-patch/socket_patch.dart:2874:41)
#36     _rootRunUnary (dart:async/zone_root.dart:56:13)
#37     _CustomZone.runUnary (dart:async/zone.dart:733:19)
#38     _CustomZone.runUnaryGuarded (dart:async/zone.dart:633:7)
#39     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#40     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#41     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
#42     _StreamController._add (dart:async/stream_controller.dart:663:7)
#43     _StreamController.add (dart:async/stream_controller.dart:618:5)
#44     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:2312:31)
#45     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1647:14)
#46     _microtaskLoop (dart:async/schedule_microtask.dart:40:35)
#47     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#48     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:127:13)
#49     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:193:5)

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 14, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Apr 14, 2026
@bkonyi

bkonyi commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

Hm looks like this change caused some failures: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8684608000406265473/+/u/run_test.dart_for_tool_integration_tests_shard_and_subshard_10_10/stdout

Looks like since we weren't properly cleaning up the widget preview processes before, we didn't hit this case. I've uploaded a fix.

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 14, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Apr 14, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request is not mergeable in its current state, likely because of a merge conflict. Pre-submit CI jobs were not triggered. Pushing a new commit to this branch that resolves the issue will result in pre-submit jobs being scheduled.

bkonyi added 4 commits April 14, 2026 15:18
The test was flaking and timing out because it requested a Hot Restart via DTD immediately after running `flutter clean` on the root project. Wiping the root project's `.dart_tool/` directory deletes `package_config.json`, which breaks the background Analysis Server and incremental compilers. Because the compiler cannot re-resolve dependencies, the Hot Restart fails and the previewer never sends the second `Connected` event, resulting in a timeout.

This fix resolves the flakiness by synchronously restoring dependencies using `flutter pub get` right after the `flutter clean` call. This restores `package_config.json` so the background compilers and Analysis Server can successfully re-read dependencies and execute the Hot Restart deterministically. We also updated process spawners to use `addTearDown` logic to ensure leaked processes are safely killed after test completion.

Fixes flutter#184985
@bkonyi bkonyi force-pushed the fix_widget_preview_smoke_test_flake branch from 98fd4df to d49f5e4 Compare April 14, 2026 19:19
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 14, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Apr 14, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 14, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Apr 14, 2026
@bkonyi

bkonyi commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

Looks like there was a bit more to this than I thought, but it seems like we're in a good state now. PTAL :)

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 14, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Apr 14, 2026

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-LGTM!

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 16, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Apr 16, 2026
Merged via the queue into flutter:master with commit 990b0a5 Apr 16, 2026
158 of 159 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 16, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 17, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Apr 17, 2026
flutter/flutter@31f1802...8e8a194

2026-04-17 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix ImageInfo.isCloneOf to correctly compare scale values (fixes #184626) (#184643)" (flutter/flutter#185203)
2026-04-17 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Roll Fuchsia Test Scripts from R2EllDf4DgBXVNuiN... to dQ4PjIJB5kZFU8Y32... (#185192)" (flutter/flutter#185199)
2026-04-17 chris@bracken.jp [iOS] Migrate FlutterLaunchEngine to Swift (flutter/flutter#185151)
2026-04-17 116356835+AbdeMohlbi@users.noreply.github.com Remove unused `FlutterRunArguments.java` file  (flutter/flutter#184160)
2026-04-17 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from R2EllDf4DgBXVNuiN... to dQ4PjIJB5kZFU8Y32... (flutter/flutter#185192)
2026-04-17 pewpewstol@gmail.com [Impeller] Fix morphology filter asymmetric dilation/erosion (flutter/flutter#184913)
2026-04-17 nate.w5687@gmail.com `AnimationStyle` methods (flutter/flutter#182333)
2026-04-17 karan@solvejet.net Fix _scheduleSystemFontsUpdate assertion during non-idle scheduler phase (flutter/flutter#184332)
2026-04-17 154381524+flutteractionsbot@users.noreply.github.com Revert "Unpin sdk package dependencies" (flutter/flutter#185186)
2026-04-16 116356835+AbdeMohlbi@users.noreply.github.com Clarify why the `child` is nullable in `AnimatedTransitionBuilder` (flutter/flutter#182995)
2026-04-16 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from IdBT8fSMYrYSip65j... to di3JdYrdE9OFu8Iyl... (flutter/flutter#185173)
2026-04-16 1063596+reidbaker@users.noreply.github.com Add dart_skills_lint to dev/tool with test and update readme instructions for new skills authors (flutter/flutter#185033)
2026-04-16 flar@google.com [Impeller] Provide std::optional getter for stroke property (flutter/flutter#185112)
2026-04-16 katelovett@google.com Validate itemExtent with geometry in RenderSliverFixedExtentBoxAdaptor (flutter/flutter#185159)
2026-04-16 152433210+mozammal-hossain@users.noreply.github.com [iOS] Clarify provisioning profile error instructions (flutter/flutter#184051)
2026-04-16 bkonyi@google.com [Widget Preview] Fix flaky integration test timeout during flutter clean (flutter/flutter#184991)
2026-04-16 engine-flutter-autoroll@skia.org Roll Dart SDK from fbddcbe0cd96 to 7c2564c18770 (2 revisions) (flutter/flutter#185143)
2026-04-16 sigurdm@google.com Unpin sdk package dependencies (flutter/flutter#184821)
2026-04-16 68919043+Istiak-Ahmed78@users.noreply.github.com Fix ImageInfo.isCloneOf to correctly compare scale values (fixes #184626) (flutter/flutter#184643)
2026-04-16 engine-flutter-autoroll@skia.org Roll Skia from 391cdbe3ffe9 to d8415c5d7b91 (2 revisions) (flutter/flutter#185141)
2026-04-16 154381524+flutteractionsbot@users.noreply.github.com Sync CHANGELOG.md from stable (flutter/flutter#185166)
2026-04-16 154381524+flutteractionsbot@users.noreply.github.com Revert "Move widget_preview_scaffold into pub workspace" (flutter/flutter#185164)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC boetger@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@bkonyi bkonyi added the cp: beta cherry pick this pull request to beta release candidate branch label Apr 17, 2026
@flutteractionsbot

Copy link
Copy Markdown
Contributor

Failed to create CP due to merge conflicts.
You will need to create the PR manually. See the cherrypick wiki for more info.

auto-submit Bot pushed a commit that referenced this pull request Apr 27, 2026
…lutter clean (#184991) (#185300)

### Issue Link:
What is the link to the issue this cherry-pick is addressing?

#185299
### Impact Description:
What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)?
Does it impact development (ex. flutter doctor crashes when Android Studio is installed),
or the shipping of production apps (the app crashes on launch).
This information is for domain experts and release engineers to understand the consequences of saying yes or no to the cherry pick.

`flutter widget-preview start` can crash on shutdown if there's an outstanding request to retrieve previews from the analysis server.

### Changelog Description:
Explain this cherry pick:
* In one line that is accessible to most Flutter developers.
* That describes the state prior to the fix.
* That includes which platforms are impacted.
See [best practices](https://github.com/flutter/flutter/blob/main/docs/releases/Hotfix-Documentation-Best-Practices.md) for examples.

`flutter widget-preview start` can encounter an unhandled exception during shutdown due to uncomplete requests.

### Workaround:
Is there a workaround for this issue?

No.

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
What are the steps to validate that this fix works?

Run `packages/flutter_tools/test/integration.shard/widget_preview_smoke_test.dart` and verify there's no crashes.
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11523)

flutter/flutter@31f1802...8e8a194

2026-04-17 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix ImageInfo.isCloneOf to correctly compare scale values (fixes #184626) (#184643)" (flutter/flutter#185203)
2026-04-17 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Roll Fuchsia Test Scripts from R2EllDf4DgBXVNuiN... to dQ4PjIJB5kZFU8Y32... (#185192)" (flutter/flutter#185199)
2026-04-17 chris@bracken.jp [iOS] Migrate FlutterLaunchEngine to Swift (flutter/flutter#185151)
2026-04-17 116356835+AbdeMohlbi@users.noreply.github.com Remove unused `FlutterRunArguments.java` file  (flutter/flutter#184160)
2026-04-17 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from R2EllDf4DgBXVNuiN... to dQ4PjIJB5kZFU8Y32... (flutter/flutter#185192)
2026-04-17 pewpewstol@gmail.com [Impeller] Fix morphology filter asymmetric dilation/erosion (flutter/flutter#184913)
2026-04-17 nate.w5687@gmail.com `AnimationStyle` methods (flutter/flutter#182333)
2026-04-17 karan@solvejet.net Fix _scheduleSystemFontsUpdate assertion during non-idle scheduler phase (flutter/flutter#184332)
2026-04-17 154381524+flutteractionsbot@users.noreply.github.com Revert "Unpin sdk package dependencies" (flutter/flutter#185186)
2026-04-16 116356835+AbdeMohlbi@users.noreply.github.com Clarify why the `child` is nullable in `AnimatedTransitionBuilder` (flutter/flutter#182995)
2026-04-16 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from IdBT8fSMYrYSip65j... to di3JdYrdE9OFu8Iyl... (flutter/flutter#185173)
2026-04-16 1063596+reidbaker@users.noreply.github.com Add dart_skills_lint to dev/tool with test and update readme instructions for new skills authors (flutter/flutter#185033)
2026-04-16 flar@google.com [Impeller] Provide std::optional getter for stroke property (flutter/flutter#185112)
2026-04-16 katelovett@google.com Validate itemExtent with geometry in RenderSliverFixedExtentBoxAdaptor (flutter/flutter#185159)
2026-04-16 152433210+mozammal-hossain@users.noreply.github.com [iOS] Clarify provisioning profile error instructions (flutter/flutter#184051)
2026-04-16 bkonyi@google.com [Widget Preview] Fix flaky integration test timeout during flutter clean (flutter/flutter#184991)
2026-04-16 engine-flutter-autoroll@skia.org Roll Dart SDK from fbddcbe0cd96 to 7c2564c18770 (2 revisions) (flutter/flutter#185143)
2026-04-16 sigurdm@google.com Unpin sdk package dependencies (flutter/flutter#184821)
2026-04-16 68919043+Istiak-Ahmed78@users.noreply.github.com Fix ImageInfo.isCloneOf to correctly compare scale values (fixes #184626) (flutter/flutter#184643)
2026-04-16 engine-flutter-autoroll@skia.org Roll Skia from 391cdbe3ffe9 to d8415c5d7b91 (2 revisions) (flutter/flutter#185141)
2026-04-16 154381524+flutteractionsbot@users.noreply.github.com Sync CHANGELOG.md from stable (flutter/flutter#185166)
2026-04-16 154381524+flutteractionsbot@users.noreply.github.com Revert "Move widget_preview_scaffold into pub workspace" (flutter/flutter#185164)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC boetger@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD cp: beta cherry pick this pull request to beta release candidate branch tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test times out often: "flutter widget-preview start doesn't crash on flutter clean"

3 participants