Skip to content

[tests] Synchronize HTTP, activity, and incremental tests - #13698

Draft
simonrozsival wants to merge 23 commits into
dev/simonrozsival/timing-device-readinessfrom
simonrozsival-timing-based-tests-audit
Draft

simonrozsival wants to merge 23 commits into
dev/simonrozsival/timing-device-readinessfrom
simonrozsival-timing-based-tests-audit

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Context: #11792

Replace timing assumptions in activity, HTTP, file-retry, and incremental-build tests with signals or observable outcomes.

Manifest activity creation

Signal the managed OnCreate from the activity and wait for that signal, rather than polling against wall-clock time. The assertion now starts only after the activity has actually reached the state needed by the test.

HTTP cancellation and disposal

Keep the peer's response or request body stalled, then observe the tagged Java worker in a native socket read or write before cancelling or disposing. Recheck the currently pending upload write, propagate early request failures, and use generous watchdogs to detect hangs. The observer retains the production CopyToAsync path; a negative-control test verifies that unrelated pending work cannot satisfy the socket probe. Dispose every stack-frame peer in a finally after inspection so repeated polling does not accumulate global references.

File retry settings

Remove the Windows locked-file thread-state polling: WaitSleepJoin, even observed across multiple retry delays, cannot establish which wait occurred. Use the existing scoped-retry test's deliberately invalid delay as a retry-specific signal instead: with the destination locked, zero retries propagates IOException, whereas one retry reaches Thread.Sleep and throws ArgumentOutOfRangeException. Verify copying and destination contents after releasing the lock, and keep Unix sharing semantics explicit. No production hooks are added. This proves entry into the retry path, not successful resumption of the same invocation after an in-flight lock release; reliable synchronization for that scenario is not exposed by the current API.

Repetitive incremental builds

Re-enable the test by asserting that unchanged builds skip compilation, packaging, and signing work and preserve package contents and timestamps. Change an Android resource, verify that the packaged resource table changes, and then verify that another unchanged build is a no-op. These checks cover incremental behavior directly without assuming that a later build must be faster.

Validation

Validation was run with all five layers applied on macOS and an API 35 arm64 emulator; intermediate branch heads were not built separately.

  • ./dotnet-local.sh test bin/TestDebug/net11.0/Xamarin.Android.Build.Tests.dll --filter 'Name~RepetiviteBuildUpdateSingleResource|Name~BuildAppWithManagedResourceParserAndLibraries' -v minimal — passed (4 tests across CoreCLR and NativeAOT).
  • ./dotnet-local.sh test bin/TestDebug/Microsoft.Android.Build.BaseTasks-Tests.dll --filter 'FullyQualifiedName~BootstrapProcessTests|Name~ProjectScopedRetries' -v minimal — passed (11 tests).
  • ./dotnet-local.sh build -t:Install -c Debug tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -p:Device=emulator-5558 -p:IncludeCategories=AndroidMessageHandlerCancellation%2CJniReferenceLeakMeasurement%2CTrimmableTypeMapRuntimeCoverage -v minimal — passed.
  • (cd tests/Mono.Android-Tests/Mono.Android-Tests && ../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Debug -p:Device=emulator-5558 -p:IncludeCategories=AndroidMessageHandlerCancellation%2CJniReferenceLeakMeasurement%2CTrimmableTypeMapRuntimeCoverage --report-trx --results-directory ../../../bin/TestDebug/ReviewCoreCLRResults) — passed 55 cases in each of 3 CoreCLR runs on API 35 arm64.
  • ./dotnet-local.sh msbuild tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -getProperty:_AndroidRuntime -p:PublishAot=true -p:Optimize=true -p:RuntimeIdentifier=android-arm64 -p:Configuration=Debug -p:Device=emulator-5558 — returned NativeAOT.
  • ./dotnet-local.sh build -t:Install -c Debug tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -p:Device=emulator-5558 -p:RuntimeIdentifier=android-arm64 -p:PublishAot=true -p:Optimize=true -p:IncludeCategories=AndroidMessageHandlerCancellation%2CJniReferenceLeakMeasurement%2CTrimmableTypeMapRuntimeCoverage -v minimal — passed.
  • (cd tests/Mono.Android-Tests/Mono.Android-Tests && ../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Debug -p:Device=emulator-5558 -p:RuntimeIdentifier=android-arm64 -p:PublishAot=true -p:Optimize=true -p:IncludeCategories=AndroidMessageHandlerCancellation%2CJniReferenceLeakMeasurement%2CTrimmableTypeMapRuntimeCoverage --report-trx --results-directory ../../../bin/TestDebug/ReviewNativeAotResults) — passed 55 cases in each of 2 NativeAOT runs.

Follow-up review validation after disposing polled stack frames and removing ambiguous retry waits:

  • dotnet test tests/Microsoft.Android.Build.BaseTasks-Tests/Microsoft.Android.Build.BaseTasks-Tests.csproj -v minimal --filter 'FullyQualifiedName~FilesTests' — passed 57, skipped 1, failed 0 on macOS.
  • ./dotnet-local.sh build -t:Install -c Debug tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -p:Device=emulator-5560 -p:IncludeCategories=AndroidMessageHandlerCancellation -v:minimal — passed, 0 warnings/errors.
  • (cd tests/Mono.Android-Tests/Mono.Android-Tests && ../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Debug -p:Device=emulator-5560 -p:IncludeCategories=AndroidMessageHandlerCancellation --report-trx --results-directory ../../../bin/TestDebug/CancellationReviewResults) — passed all 11 tests on a dedicated API 35 arm64 emulator using CoreCLR. The emulator was stopped and removed afterward.

The Windows-specific locked-file retry assertions were not exercised on this macOS host. The Java socket-stack probe was not exercised on Android API levels other than 35. The follow-up stack-frame disposal change was run on CoreCLR, not rerun on NativeAOT.

simonrozsival and others added 8 commits November 21, 2026 00:12
Assert the generated resource classes without requiring the parser to finish within a machine-dependent time limit.

Co-authored-by: Copilot App <[email protected]>
Verify that an unchanged resource build skips compilation, and that design-time builds generate resource designers without invoking Android compilation or packaging tasks (including Aapt2Compile and R8), rather than comparing wall-clock build durations. Match the detailed MSBuild log format, which has no task ID suffix, so both positive and negative assertions are meaningful.

Co-authored-by: Copilot App <[email protected]>
Keep the target execution checks and verify that an unchanged build skips compilation instead of comparing build durations. Pin the ABI so the touched intermediate assemblies match the generated ones, including on arm64 hosts.

Co-authored-by: Copilot App <[email protected]>
App startup does not mean the file watcher is ready. Retry distinct edits until the update handler reports success rather than sleeping before a single edit. Pass the selected adb serial to dotnet watch so the test works when multiple devices are connected.

Co-authored-by: Copilot App <[email protected]>
Have the fake tool signal that it has started so cancellation exercises the running process without a fixed startup delay. Use a script-relative marker path on Windows to avoid embedding a possibly non-ASCII absolute path in the batch file.

Co-authored-by: Copilot App <[email protected]>
Observe the main thread entering its wait before making the worker P/Invoke, and wait for competing Java threads to block in Runtime.loadLibrary0 before continuing the nested load, instead of assuming a short sleep is enough. Report a failure if contention is not observed.

Co-authored-by: Copilot App <[email protected]>
Exercise default and custom retry counts without depending on the lock holder being scheduled within the retry window. Simulate a sharing violation on Unix, where deleting an open file succeeds, and keep the directory locked through every configured retry.

Assert the exact number of attempts, including the zero-retry case, which must fail without deleting the directory.

Co-authored-by: Copilot App <[email protected]>
Observe the polling phase before cancellation and use a generous hang watchdog instead of comparing elapsed time with a tight threshold.

Co-authored-by: Copilot App <[email protected]>
simonrozsival and others added 13 commits November 21, 2026 16:59
`NativeLibraryLoadTests.ExemptJniLibraryLoadsOnWorkerThreadWithBlockedMainThread(False)`
failed once in CI (AzDO build 1693158, "MSBuild+Emulator 3"): neither
`WORKER_JNI_LIBRARY_LOAD_COMPLETED` nor `WORKER_JNI_LIBRARY_LOAD_FAILED`
appeared within the 90s `MonitorAdbLogcat()` timeout, and the automatic
retry passed.  The job succeeded, so no logcat artifact was uploaded,
and the only evidence was the assertion message.  The cause remains
unconfirmed: local runs on an API 29 emulator did not reproduce it.

Make the next occurrence diagnosable without changing what the test
asserts:

  * The app logs `WORKER_JNI_LIBRARY_LOAD_PROGRESS:<step>` markers on
    the main, worker, callback, and reader threads, and the assertion
    messages report the last marker seen.

  * `JniLoadProbe` starts a Java watchdog thread which, if the activity
    has not finished after 65s, logs every Java thread's state and stack
    via `Thread.getAllStackTraces()`.  This works even if managed code
    cannot run.  The worker-join timeout path dumps the same information
    before logging its existing failure marker.

  * On failure the host runs bounded, best-effort `adb` commands
    (`pidof`, `ps -T`, filtered `dumpsys activity activities`, and
    `logcat -d`), saves the full logcat as an attachment, and writes a
    filtered excerpt to the test's standard output.  Command timeouts,
    non-zero exit codes, and exceptions are reported in that output
    rather than thrown, so they cannot mask the original assertion.

Diagnostics go to standard output because CI task logs keep the
standard output of failed first attempts even when the retry passes;
in build 1693158 the first attempt's assertion and standard output
appear in the task log before the retry's results.

Co-authored-by: Copilot App <[email protected]>
Verify that output is captured and draining completes while the pipe-holding descendant is still alive. Use a generous hang watchdog instead of a narrow elapsed-time assertion, and clean up the test-owned descendant.

Co-authored-by: Copilot App <[email protected]>
Give the alternate environment input a known old timestamp (also on the project item, so saving the project does not rewrite it) and compare native object contents after changing the managed build flavor.

Co-authored-by: Copilot App <[email protected]>
Use the existing task-count and rule-content assertions to verify regeneration without requiring successive writes to have distinct timestamps.

Co-authored-by: Copilot App <[email protected]>
Compare initial outputs against a sentinel on the same filesystem and give existing typemaps a known old timestamp before checking regeneration.

Co-authored-by: Copilot App <[email protected]>
Track and clean up the pipe-holding child, using its PID file if the output handshake fails. Assert that draining reports incomplete output while the child is still alive, with a generous hang watchdog instead of a narrow elapsed-time threshold.

Co-authored-by: Copilot App <[email protected]>
The fixture already checks the requested timezone property before launching a fresh app process; remove the additional fixed sleep. Use the configured adb target when installing the fixture.

Co-authored-by: Copilot App <[email protected]>
Observe the framework services stopped by the Android stop command, with exit-code-aware polling bounded by a single deadline, and require the boot-completed signal and expected locale property before launching the app, instead of sleeping for fixed intervals. Use the configured adb target when installing the fixture.

Co-authored-by: Copilot App <[email protected]>
Keep the state-based worker and collection assertions while allowing for slow scheduling on loaded devices. Preserve zero-duration timeout cases.

Co-authored-by: Copilot App <[email protected]>
Wait for the activity to signal its managed OnCreate instead of polling against a wall-clock deadline.

Co-authored-by: Copilot App <[email protected]>
Cancellation and disposal tests waited a fixed interval and then asserted short elapsed times. Instead, wait for the stalled peer and observe the request's Java worker in a native socket read or write before cancelling or disposing. Recheck the current upload write and race readiness against early request failures.

Keep the production CopyToAsync path, use generous hang watchdogs, and verify that unrelated pending work does not satisfy the socket probe.

Co-authored-by: Copilot App <[email protected]>
Observe the Windows copy thread waiting on a retry while the destination is locked, instead of holding the lock for a fixed delay, and preserve the Unix open-file behavior separately. Use an invalid retry delay to distinguish zero from one retry for copy and XML writes without asserting elapsed time.

Co-authored-by: Copilot App <[email protected]>
Build timings vary with machine load, so a second build being slower does not show that incremental work was repeated. Replace the timing comparison with assertions that unchanged builds skip compilation, packaging, and signing work and preserve package outputs.

Change an Android resource to verify that its packaged resource table changes, then confirm the next build is again a no-op.

Fixes: #11792

Co-authored-by: Copilot App <[email protected]>
@simonrozsival
simonrozsival force-pushed the simonrozsival-timing-based-tests-audit branch from 53450a2 to 6080ce0 Compare November 21, 2026 16:00
simonrozsival and others added 2 commits November 21, 2026 22:26
AndroidMessageHandlerCancellationTests.IsInSocketOperation() polls
Thread.GetStackTrace() roughly every 20ms for up to 30s; dispose the
returned StackTraceElement peers so a failing run does not accumulate
thousands of global references.

FilesTests: any WaitSleepJoin observation was accepted as proof that
CopyIfChanged() entered its retry loop. Require the copy thread to still
be waiting more than two retry delays after the first observed wait
while the destination lock is held, which means the copy woke, failed
against the lock, and slept again.

Co-authored-by: Copilot App <[email protected]>
WaitSleepJoin observations separated by two retry delays cannot identify the wait or prove that CopyIfChanged attempted the locked destination. Remove this heuristic rather than treating elapsed time as evidence of a retry.

Reuse CopyIfChanged_ProjectScopedRetries: with FileShare.None held, zero retries propagates IOException; one retry with an invalid delay reaches Thread.Sleep and throws ArgumentOutOfRangeException. This directly observes the retry path without a production hook. Extend the test to verify copying and destination contents after releasing the lock.

This does not claim coverage of one invocation successfully resuming after an in-flight lock release; there is no reliable retry notification exposed by CopyIfChanged for that synchronization.

Validation: dotnet test tests/Microsoft.Android.Build.BaseTasks-Tests/Microsoft.Android.Build.BaseTasks-Tests.csproj -v minimal --filter 'FullyQualifiedName~FilesTests' passed 57 tests, skipped 1 on macOS. Windows-specific retry assertions were not exercised.

The AndroidMessageHandlerCancellation category also passed all 11 tests on a dedicated API 35 arm64 emulator after building/installing the updated test APK. The emulator was stopped and removed afterward.

Co-authored-by: Copilot App <[email protected]>

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant