Skip to content

fix(Linux CI test): Wait for the first canvas paint in Blazor CPU sample tests - #5353

Merged
mattleibow merged 1 commit into
mono:mainfrom
VirgilMing:dev/issue-5312-blazor-first-paint
Oct 15, 2026
Merged

mattleibow merged 1 commit into
mono:mainfrom
VirgilMing:dev/issue-5312-blazor-first-paint

Conversation

@VirgilMing

@VirgilMing VirgilMing commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

One liner

This PR fixes a flaky test in GitHub Linux CI pipeline.

Description

The Blazor CPU sample can expose a visible canvas before its raster interop has presented any pixels. Capturing at that point produces an empty drawing area and fails the existing golden-image assertion. This was observed in the Linux Host job of build 1634806 for #5352, with 869,440 of 1,152,000 pixels differing (75.472%).

Wait for the CPU canvas's first opaque pixel before capturing it. This sample paints an opaque background, and the raster view presents the frame in one putImageData call. The existing image comparison still checks the complete rendered scene.
Exercise both normal initialization and a regression case that delays the raster interop module by one second; the delay is fault injection in the regression case, while readiness is determined by pixels.

Historical scope: git blame identifies the current refactored test's arrival through #5312; it does not establish the earliest introduction of this readiness gap.
The same wait-for-visible-then-capture sequence already appears in older revision 9b143bac's BasicSampleTests.cs. Earlier build 1632173 reported four Linux Samples errors, but their contents have not been inspected and are not classified as this blank-canvas failure. The final #5312 and the merged-main Linux Host runs passed. The earliest introduction is not traced here. #5352 is the verified blank-canvas observation; these historical results do not establish its failure rate or exclude an environment-specific trigger.

Related issues

Related to #5312. Observed while validating #5352.

Required skia PR

None.

Areas affected

  • Managed API (binding/)
  • Native / C API (externals/skia/src/c, include/c)
  • Generated P/Invoke bindings
  • Native dependency or Skia update (libpng, HarfBuzz, FreeType, zlib, milestone bump, …)
  • Views & integrations (MAUI, Uno, WPF, WinUI, Blazor, …)
  • Rendering output / visual behavior
  • Performance
  • Tests
  • Build, packaging, or CI
  • Documentation or samples

Changes

None to public API, ABI, or product rendering. The CPU screenshot test waits for an actual frame and covers delayed initialization. Its golden image and strict 0.075% differing-pixel tolerance are retained.

Testing

Local Gentoo/glibc x64, .NET SDK 10.0.401, Playwright 1.55.0, Chromium Headless Shell 140.0.7339.16 (revision 1187). The generated sample consumes the exact 4.156.0-pr.5352.26514.6 package cohort from producing build 1634806; the test runner is built from this branch's source.

Check Result
Unmodified CPU test, same source commit f1e82f7, five fresh runs 5 passed, 0 failed. No natural reproduction in this local sample; this is not an estimate of CI failure frequency.
New delayed-initialization case with the old capture condition Normal initialization passed; delayed initialization failed with the same empty drawing area and 75.472% pixel difference.
Both CPU cases after adding pixel readiness, repeated twice 4 passed, 0 failed, 0 skipped.
Sample infrastructure and discovery tests 82 passed, 0 failed, 0 skipped.
Unfiltered Console solution 6450 passed, 0 failed, 38 existing declared skips.

The controlled case proves that the missing readiness condition can produce the observed image failure. The original CI run was not instrumented, so its precise timing/environment trigger remains unverified. A preliminary attempt made before browser installation completed reported a missing executable and is excluded from image-failure statistics.

Commands:

dotnet test tests/SkiaSharp.Tests.Samples/SkiaSharp.Tests.Samples.csproj -c Release --no-build --no-restore -p:TargetFramework=net10.0 -p:TargetFrameworks=net10.0 -- --filter-method '*BlazorWebAssemblyCpuSampleRuns*' --report-trx
dotnet test tests/SkiaSharp.Tests.Samples/SkiaSharp.Tests.Samples.csproj -c Release --no-build --no-restore -p:TargetFramework=net10.0 -p:TargetFrameworks=net10.0 -- --filter-class 'SkiaSharp.Tests.Samples.SampleInfrastructureTests' --filter-class 'SkiaSharp.Tests.Samples.SampleDiscoveryTests' --report-trx
dotnet test tests/SkiaSharp.Tests.Console.slnx -p:TargetFramework=net10.0 -p:TargetFrameworks=net10.0

The Console solution reused source-built Linux natives and isolated DejaVu font fixtures through Fontconfig, as in the producing local validation. No skip policy was changed.

Unverified: other operating systems and architectures, the full Samples Build/Docker/device/Uno groups, and this branch's remote CI.
Also, Gentoo uses Playwright's Ubuntu 20.04 fallback browser build. Local WASM tools/runtime are 10.0.12, while the producing CI sample used 10.0.6. These differences limit direct inference about production CI frequency.

Checklist

  • Tests added or updated (normal and delayed CPU initialization)
  • Changes above lists all public API and behavioral changes
  • New/changed public API? Added or updated accurate source /// documentation and regenerated bindings when applicable — N/A: test-only change
  • Native change? Companion mono/skia PR linked above and bindings regenerated — N/A: no native or C API change

@github-actions

Copy link
Copy Markdown
Contributor

📦 Try the packages from this PR

Warning

Do not run these scripts without first reviewing the code in this PR.

Step 1 — Download the packages

bash / macOS / Linux:

curl -fsSL https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.sh | bash -s -- 5353

PowerShell / Windows:

iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 5353"

Step 2 — Add the local NuGet source

dotnet nuget add source ~/.skiasharp/hives/pr-5353/packages --name skiasharp-pr-5353
More options
Option Description
--successful-only / -SuccessfulOnly Only use successful builds
--force / -Force Overwrite previously downloaded packages
--list / -List List available artifacts without downloading
--build-id ID / -BuildId ID Download from a specific build

Or download manually from Azure Pipelines — look for the nuget artifact on the build for this PR.

Remove the source when you're done:

dotnet nuget remove source skiasharp-pr-5353

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@VirgilMing! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@VirgilMing VirgilMing mentioned this pull request Oct 14, 2026
4 of 14 tasks
@VirgilMing
VirgilMing marked this pull request as ready for review October 14, 2026 16:25
@VirgilMing VirgilMing changed the title Wait for the first canvas paint in Blazor CPU sample tests fix(Linux CI test): Wait for the first canvas paint in Blazor CPU sample tests Oct 14, 2026
A visible canvas can still be empty while the raster interop module loads.
Wait for the sample's first opaque pixel before capturing the existing
golden image, and exercise delayed module initialization as a regression.

The delayed case fails with the old condition and passes with pixel
readiness. Normal initialization, infrastructure/discovery tests, and the
unfiltered Console solution pass locally.

Related to mono#5312; observed while validating mono#5352. The earliest introduction
of the readiness gap is not established by the current refactored-file blame.
@VirgilMing
VirgilMing force-pushed the dev/issue-5312-blazor-first-paint branch from e20b715 to 2a92af1 Compare October 15, 2026 06:56
@mattleibow
mattleibow merged commit 7bd9489 into mono:main Oct 15, 2026
100 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in SkiaSharp Backlog Oct 15, 2026
mattleibow pushed a commit that referenced this pull request Oct 15, 2026
Build on #5353's pixel readiness fix without a fixed fault-injection delay. Hold raster initialization until the readiness predicate observes a real transparent pixel, then permit painting and retain the full golden comparison. Release pending routes during failure cleanup.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 1d3be5b1-5a0b-452c-8a04-703fc4dd1ae1
@VirgilMing
VirgilMing deleted the dev/issue-5312-blazor-first-paint branch October 16, 2026 02:14
mattleibow added a commit that referenced this pull request Oct 17, 2026
)

Stabilize browser sample captures and stable Uno startup (#5361)

Context: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1636281
Context: #5353
Context: https://github.com/mono/SkiaSharp/pull/5293/checks?check_run_id=116262705576
Context: unoplatform/uno#24260
Changes: unoplatform/uno@f4d493c...da217df

Handle CSS transitions, eventual image readiness, and Uno splash dismissal
at their respective boundaries rather than relaxing golden comparisons.
Keep the Basic Uno sample on a stable SDK and retain repository mirrors
for dependency resolution.

~~ Finish CSS transitions before screenshot capture ~~

The Windows Blazor drawing test cleared its canvas correctly, but its
cleared-page screenshot differed by 1906 pixels inside the Clear button.
Its hover-exit background transition was still running after the canvas
readiness assertions had passed.

Set ScreenshotAnimations.Disabled in BrowserRunningApp.Screenshot so
Playwright finishes finite CSS transitions during capture. This does not
wait for WASM canvas painting. Retain the drawing pixel assertions and
existing comparison thresholds; no Blazor references change.

Verify the capture behavior with a transition paused halfway: the captured
100x100 swatch must contain its final color, not the intermediate color.

~~ Give eventual image readiness one bounded comparison loop ~~

A visible Blazor CPU canvas can precede its first raster presentation.
The pixel-readiness fix in #5353 addressed that gap, but separate pixel
and image checks give startup different readiness conditions and deadlines.

Add an opt-in SampleImage.Validate capture-delegate overload that returns
the matching image path. Retry dimension and pixel mismatches against the
reviewed reference, using the existing comparison options. Default to a
two-second budget with 100ms polling; the CPU startup test explicitly
allows ten seconds and returns on the first matching capture.

Replace BlazorWebAssemblyCpuSampleRuns(delayFirstPaint), its one-second
module-delay case, and its opaque-pixel probe with a normal startup test
using the complete golden image as its readiness condition. Do not apply
eventual matching globally to drawing or GPU assertions: a matching frame
does not establish that every intermediate frame was correct.

Limit each capture await to the remaining budget and test cancellation.
WaitAsync stops waiting; it does not cancel the underlying capture.
Propagate capture errors and cancellation rather than treating them as
image mismatches. Missing references and corrupt images also fail without
retrying. Preserve one-shot validation and produce the usual diagnostics
when a completed mismatch persists until the deadline.

Exercise transient and persistent mismatches, dimension changes, retained
diagnostics, invalid deadlines, stalled captures, and error propagation.
A browser test captures an incorrect frame followed by the expected frame;
the console-error test verifies browser errors still escape through the
capture loop.

~~ Adopt stable Uno without accepting unrelated image changes ~~

Update the Basic Uno sample from Uno.Sdk 6.6.0-dev.208 to stable 6.7.30,
which selects runtime 6.7.135. Keep repository package sources unchanged:
the required dependencies are supplied through the existing mirrors.
Add a contract test for the artifacts, dotnet-public, and dotnet-eng
source/mapping keys; generated SkiaSharp and HarfBuzzSharp consumers
remain restricted to staged artifacts.

The newer navigation template changes top-navigation spacing. Review and
update the nine Uno references for that layout change: 1556 CPU navigation
pixels and 1582 Drawing navigation pixels per reference. Every pixel below
the 49-pixel navigation header remains unchanged, including scene content,
strokes, the Clear button, and drawing controls. Stable CPU and drawing
tests pass these references without changing their tolerances.

~~ Keep recording until Uno dismisses its startup splash ~~

The Windows Uno failure remained on .uno-loader until startup timed out.
Reproduce the symptom locally on stable 6.7.30 with 4x Chromium CPU
throttling: the loader stays visible for 60 seconds despite an existing
canvas and no browser errors.

Uno subscribes to CompositionTarget.FrameRendered, then requests a
presentation through IXamlRootHost.InvalidateRender. Presentation can
reuse an existing recording without raising the event needed to remove
the splash. The upstream correction requests a new recorded frame, but
that correction is absent from the selected stable runtime.

Add a WebAssembly-only partial App hook before window activation.
Temporarily subscribe to the public CompositionTarget.Rendering event,
whose stable implementation requests recorded frames. Let Uno remove
its own loader, then unsubscribe. Also stop on window close. An
independent non-repeating 60-second dispatcher timer unsubscribes and
reports an explicit error if dismissal never completes. Do not hide the
loader or substitute screenshot retries for application recovery.

The workaround passed 32 local cold starts, including 20 consecutive
4x-throttled starts. Observation confirmed cleanup after natural dismissal.
A fault-injected observer that never reported dismissal triggered the
timeout error and stopped observing. These checks support the workaround,
not a guarantee over every scheduling interleaving.

Retain the existing normal Uno startup, rendering, navigation, drawing,
and clear tests without permanent loader-query instrumentation. Remove
the workaround when the sample adopts a runtime containing the upstream
recorded-frame correction.

The final head passes the Windows, Linux, and macOS sample Host and Build
checks and both sample Docker checks.

Co-authored-by: Matthew Leibowitz <[email protected]>
Co-authored-by: Virgil Ming <[email protected]>
Co-authored-by: Copilot App <[email protected]>
@github-actions github-actions Bot added this to the 4.156.0-rc.1 milestone Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants