Skip to content

Garbage collector test for menu_anchor sometimes flakes #154858

@matanlurey

Description

@matanlurey

#154843 flakes while running Mac framework_tests_impeller, even though its not possible that any of the code in this PR affected this test suite.

The specific failure is as follows:

06:10 +7937 ~21: /Volumes/Work/s/w/ir/x/w/flutter/packages/flutter/test/material/menu_anchor_test.dart: Garbage collector destroys child _MenuAnchorState after parent is closed
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: null
  Actual: _SubmenuButtonState:<_SubmenuButtonState#31f73(lifecycle state: defunct, not mounted)>

When the exception was thrown, this was the stack:
#4      main.<anonymous closure> (file:///Volumes/Work/s/w/ir/x/w/flutter/packages/flutter/test/material/menu_anchor_test.dart:4508:7)
<asynchronous suspension>
#5      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:189:15)
<asynchronous suspension>
#6      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1032:5)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)

This was caught by the test expectation on the following line:
  file:///Volumes/Work/s/w/ir/x/w/flutter/packages/flutter/test/material/menu_anchor_test.dart line 4508
The test description was:
  Garbage collector destroys child _MenuAnchorState after parent is closed

This test was somewhat recently added in #149586.

The following diff is somewhat suspicious:

+ // Garbage collect. 1 should be enough, but 3 prevents flaky tests.
+ await tester.runAsync<void>(() async {
+   await forceGC(fullGcCycles: 3);
+ });

I suspect if we don't know why a single forceGC doesn't work, we can't guarantee 3 will work either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: flakeTests that sometimes, but not always, incorrectly passteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions