Skip to content

[tests] Use cooperative cancellation for ViewActionCallbackTests - #13822

Open
simonrozsival wants to merge 2 commits into
mainfrom
simonrozsival-fix-viewactioncallback-flaky-test
Open

simonrozsival wants to merge 2 commits into
mainfrom
simonrozsival-fix-viewactioncallback-flaky-test

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: d0ccf3372686034eb063df8d471bc8d0b58198a3

Dimension Assessment Rationale
Change confidence 9/10 ↑ All 7 ViewActionCallbackTests passed on emulator-5556.
↑ Assertions and regression coverage are unchanged.
↓ CI for this revision has not run.
Diagnosis confidence 9/10 ↑ The failure was in activity readiness before the callback test body; logcat showed a slow first traversal and severe system frame skips.
Evidence fit 9.5/10 ↑ The 10-second readiness wait matches the reported timeout; the retry and 40 other runs passed.

Context: #13749

The activity signals readiness only after its first traversal attaches the view. In build 1703649, the Debug run timed out in WithActivity before the callback test body ran; logcat showed a slow first frame and system_server skipping up to 153 frames, consistent with emulator contention rather than a callback regression. The APKs 1 retry succeeded, and the 40 other configuration runs checked since the test was introduced had no failures.

Replaced the per-wait TimeSpan timeouts with the test's cancellation token and bounded the four asynchronous activity tests with a 60-second cooperative test timeout. Assertions and regression coverage are unchanged.

Validation:

  • ./dotnet-local.sh build -t:Install -c Debug -p:Device=emulator-5556 tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -v:q -nologo — passed.
  • From tests/Mono.Android-Tests/Mono.Android-Tests: ../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Debug -p:Device=emulator-5556 --report-trx --results-directory ../../../bin/TestDebug/TestResults2 — passed: 1143 passed, 1 skipped, 0 failed; all 7 ViewActionCallbackTests cases passed.

simonrozsival and others added 2 commits November 28, 2026 22:06
ViewActionCallbackTests.RemoveCallbacksCancelsScheduledDrawable timed out
in build 1703649 (macOS APKs 1, Debug) waiting 10s for the activity to
report readiness. Readiness is signalled from a View.Post() queued before
attach, so it waits for the first traversal. On the loaded emulator the
first frame's measure/layout took ~3.95s and system_server skipped up to
153 frames; the callback test body never ran.

Use the same 30s bound already used for the posted-work wait.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Replace the per-wait TimeSpan timeouts with the MSTest cancellation
token, bounding each activity-based test with
[Timeout (60_000, CooperativeCancellation = true)] as other
Mono.Android-Tests do.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 28, 2026 21:25

Copilot AI 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.

🟡 Changes recommended

Teardown uses the test’s canceled token after a timeout, allowing callback removal, disposal, and activity cleanup to remain pending and overlap subsequent tests.

1 open issue
What changed in this PR

This PR updates ViewActionCallbackTests to tolerate slow activity startup on contended emulators by using cooperative test cancellation instead of separate per-wait deadlines.

Changes:

  • Injects TestContext and passes its cancellation token through asynchronous helpers.
  • Adds a 60-second cooperative timeout to the four asynchronous test methods.
  • Preserves existing callback assertions and regression coverage.
File Description
tests/​Mono.Android-Tests/​Mono.Android-Tests/​Android.Views/​ViewActionCallbackTests.cs Replaces fixed wait deadlines with test cancellation and adds cooperative timeouts.

Review effort: Balanced

}
activity.Finish ();
});
}, cancellationToken);

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants