Skip to content

Commit 5b1bdd5

Browse files
committed
test(ios): keep the busy alert fixture busy for the test's whole alert budget
The fixture's fixed 20 s backstop could stop the in-flight animation while a contended host was still resolving the alert under the 60 s allowance, so a correct activation read "Answered after the app went idle". The test now passes the backstop as resolution allowance plus activation deadline.
1 parent 860163b commit 5b1bdd5

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,21 @@ @implementation AgentDeviceRunnerViewController
8282
// may receive an event: the app keeps reporting work in flight, which is the state that cost an alert
8383
// command its whole deadline in #2546. It stops the moment an alert button is answered, since that
8484
// answer is the event the runner is trying to land, and the backstop stops it even when no answer
85-
// arrives so a regressed run finishes rather than waiting out XCTest's own timeout. A layer
85+
// arrives so a regressed run finishes rather than waiting out XCTest's own timeout. The test passes
86+
// the backstop after `--agent-device-alert-activation-busy`, sized to outlast its whole resolution
87+
// and activation budget, so a slow host cannot end the busy state before the answer lands. A layer
8688
// animation on its own is not enough; only a UIView animation counts as in-flight work here.
87-
static NSTimeInterval const kAgentDeviceAlertActivationBusyWindow = 20.0;
89+
static NSTimeInterval AgentDeviceAlertActivationBusyWindow(void) {
90+
NSArray<NSString *> *arguments = NSProcessInfo.processInfo.arguments;
91+
NSUInteger flag = [arguments indexOfObject:@"--agent-device-alert-activation-busy"];
92+
return flag + 1 < arguments.count ? arguments[flag + 1].doubleValue : 0;
93+
}
8894

8995
- (void)startAlertActivationBusy {
9096
if (self.alertActivationBusyBackstop != nil) {
9197
return;
9298
}
93-
self.alertActivationBusyBackstop = [NSTimer scheduledTimerWithTimeInterval:kAgentDeviceAlertActivationBusyWindow
99+
self.alertActivationBusyBackstop = [NSTimer scheduledTimerWithTimeInterval:AgentDeviceAlertActivationBusyWindow()
94100
target:self
95101
selector:@selector(stopAlertActivationBusy)
96102
userInfo:nil

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertObservationTests.swift‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ extension RunnerTests {
6060
func testAlertActivationIgnoresAnAppThatNeverSettlesBeforeTheDeadline() throws {
6161
app.launchArguments = [
6262
"--agent-device-alert-replacement-regression",
63-
"--agent-device-alert-activation-busy"
63+
"--agent-device-alert-activation-busy",
64+
String(RunnerTests.alertResolutionAllowance + RunnerTests.alertActivationDeadline)
6465
]
6566
app.launch()
6667
defer {
@@ -72,9 +73,10 @@ extension RunnerTests {
7273

7374
let response = handleAlert(alert, action: "accept", deadline: Date().addingTimeInterval(RunnerTests.alertActivationDeadline))
7475

75-
// The fixture keeps an animation in flight until a button is answered or its 20 s backstop stops
76-
// it, and an in-flight animation is what XCTest waits out before it synthesises an event. An
77-
// answer that arrives while the app is still busy is one activation did not wait to idle (#2546).
76+
// The fixture keeps an animation in flight until a button is answered or its backstop, which
77+
// outlasts resolution plus activation, stops it, and an in-flight animation is what XCTest waits
78+
// out before it synthesises an event. An answer that arrives while the app is still busy is one
79+
// activation did not wait to idle (#2546).
7880
XCTAssertTrue(response.ok, String(describing: response.error))
7981
XCTAssertEqual(app.staticTexts["agent-device-alert-actions"].label, "First actions: 1; replacement actions: 0")
8082
XCTAssertEqual(app.staticTexts["agent-device-alert-busy-answer"].label, "Answered while busy")

0 commit comments

Comments
 (0)