From 36dd30866be87453052309a94ba9da6af8ae1c4a Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Fri, 20 Nov 2026 17:39:51 +1100 Subject: [PATCH 1/2] test(ios): check the navigation glass state often instead of once a second testNavigationGlassMergesAndRestoresInBothDirections timed out on CI (run 44682658228) waiting 2 s for the side surfaces of MergingNavigationGlass to fade out after setMenuOpen(true), a 0.18 s animation. The test waited with XCTNSPredicateExpectation, which evaluates its predicate about once a second: the test's four waits take about 4 s in passing runs, 1 s each for a 0.18 s animation. A 2 s timeout therefore gets one or two evaluations. RunnerTests runs inside the Flutter app, and when that app holds the main thread across those evaluations the wait expires even though the animation has long finished. In the failing run the 2 s timeout was reported 5.2 s after the test started. Replace both waits with a `waitUntil` helper that checks the condition every 10 ms on the main actor for up to 10 s, the budget the other RunnerTests callbacks use. It checks the condition before the deadline on every pass, so a main-thread stall of any length is followed by one more check rather than a timeout. The conditions and the assertions after them are unchanged, and the test no longer spends 4 s waiting. The cause is inferred from the CI timings and the code. Not compiled or run locally; `swiftc -parse` accepts the file. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Matt Toohey --- mobile/ios/RunnerTests/RunnerTests.swift | 32 +++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/mobile/ios/RunnerTests/RunnerTests.swift b/mobile/ios/RunnerTests/RunnerTests.swift index d7ec5c9a28c..6f234ae1eda 100644 --- a/mobile/ios/RunnerTests/RunnerTests.swift +++ b/mobile/ios/RunnerTests/RunnerTests.swift @@ -196,10 +196,9 @@ class RunnerTests: XCTestCase { XCTAssertEqual(glass.centerSurface.bounds.width, vertical ? 56 : 112) XCTAssertEqual(glass.centerSurface.center, CGPoint(x: glass.bounds.midX, y: glass.bounds.midY)) glass.setMenuOpen(true, animator: nil) - let merged = XCTNSPredicateExpectation(predicate: NSPredicate { _, _ in + await waitUntil("the side surfaces have merged") { glass.leftSurface.alpha == 0 && glass.rightSurface.alpha == 0 - }, object: nil) - await fulfillment(of: [merged], timeout: 2) + } XCTAssertEqual(glass.leftSurface.transform.tx, vertical ? 0 : 100, accuracy: 0.01) XCTAssertEqual(glass.leftSurface.transform.ty, vertical ? 72 : 0, accuracy: 0.01) XCTAssertEqual(glass.rightSurface.transform.tx, vertical ? 0 : -100, accuracy: 0.01) @@ -207,11 +206,10 @@ class RunnerTests: XCTestCase { glass.setMenuOpen(false, animator: nil) glass.setMenuOpen(true, animator: nil) glass.setMenuOpen(false, animator: nil) - let restored = XCTNSPredicateExpectation(predicate: NSPredicate { _, _ in + await waitUntil("the side surfaces are restored") { glass.leftSurface.alpha == 1 && glass.rightSurface.alpha == 1 && glass.leftSurface.transform == .identity && glass.rightSurface.transform == .identity - }, object: nil) - await fulfillment(of: [restored], timeout: 2) + } } } @@ -2543,6 +2541,28 @@ extension XCTestCase { .first { $0.activationState == .foregroundActive } } + /// Returns once `condition` holds, and fails the test if it never does. + /// + /// `XCTNSPredicateExpectation` evaluates its predicate about once a second, + /// so a short wait gets one or two looks and a busy host main thread can + /// use them all up. This checks every few milliseconds, and checks once + /// more before giving up however late the main thread comes back. + @MainActor + func waitUntil( + _ description: String, timeout: TimeInterval = 10, + file: StaticString = #filePath, line: UInt = #line, + _ condition: @MainActor () -> Bool + ) async { + let deadline = Date().addingTimeInterval(timeout) + while !condition() { + guard Date() < deadline else { + XCTFail("Timed out waiting until \(description)", file: file, line: line) + return + } + try? await Task.sleep(nanoseconds: 10_000_000) + } + } + /// Fulfilled once `window` is the key window and shows `root`'s view. @MainActor func keyWindowReady(_ window: UIWindow, showing root: UIViewController) -> XCTestExpectation { From 7cdfda6fe67a2013e738758c953dd19ecf52eb07 Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Thu, 19 Nov 2026 23:33:15 -0800 Subject: [PATCH 2/2] test(ios): wait for the navigation glass animation to finish The merged and restored values are set as soon as an animation starts, so both waits passed on their first check. Also require that the side layers have no running animations, so the close that follows starts from a finished animator. Co-authored-by: studio Signed-off-by: Tom Brow (cherry picked from commit 05190369eef50ac538c53ed58ee3213244f25db2) Signed-off-by: Matt Toohey --- mobile/ios/RunnerTests/RunnerTests.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mobile/ios/RunnerTests/RunnerTests.swift b/mobile/ios/RunnerTests/RunnerTests.swift index 6f234ae1eda..f424dcbb118 100644 --- a/mobile/ios/RunnerTests/RunnerTests.swift +++ b/mobile/ios/RunnerTests/RunnerTests.swift @@ -196,8 +196,13 @@ class RunnerTests: XCTestCase { XCTAssertEqual(glass.centerSurface.bounds.width, vertical ? 56 : 112) XCTAssertEqual(glass.centerSurface.center, CGPoint(x: glass.bounds.midX, y: glass.bounds.midY)) glass.setMenuOpen(true, animator: nil) + // The values below are set as soon as an animation starts. Also wait + // for the animation to finish, so the close that follows starts from a + // finished animator, as it does when someone closes the menu. await waitUntil("the side surfaces have merged") { - glass.leftSurface.alpha == 0 && glass.rightSurface.alpha == 0 + glass.leftSurface.alpha == 0 && glass.rightSurface.alpha == 0 && + (glass.leftSurface.layer.animationKeys() ?? []).isEmpty && + (glass.rightSurface.layer.animationKeys() ?? []).isEmpty } XCTAssertEqual(glass.leftSurface.transform.tx, vertical ? 0 : 100, accuracy: 0.01) XCTAssertEqual(glass.leftSurface.transform.ty, vertical ? 72 : 0, accuracy: 0.01) @@ -208,7 +213,9 @@ class RunnerTests: XCTestCase { glass.setMenuOpen(false, animator: nil) await waitUntil("the side surfaces are restored") { glass.leftSurface.alpha == 1 && glass.rightSurface.alpha == 1 && - glass.leftSurface.transform == .identity && glass.rightSurface.transform == .identity + glass.leftSurface.transform == .identity && glass.rightSurface.transform == .identity && + (glass.leftSurface.layer.animationKeys() ?? []).isEmpty && + (glass.rightSurface.layer.animationKeys() ?? []).isEmpty } } }