Skip to content

Commit 2738700

Browse files
committed
test(aws): pin that the allocation deadline outlives the 120s startup default; drop empty import
Review follow-ups on 7f9d148: a virtual-clock test (Date.now advanced 10s per poll, RUNNING at 150s, deadline 300s) that fails on the old min(default, deadline) logic and passes now; and the empty 'import {} from kernel/errors' left in maestro/shared.ts is removed.
1 parent 7f9d148 commit 2738700

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

‎packages/maestro/src/internal/shared.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {} from '@agent-device/kernel/errors';
21
import type { Point, Rect, SnapshotNode } from '@agent-device/kernel/snapshot';
32

43
export function stripUndefined<T extends Record<string, unknown>>(value: T): T {

‎packages/provider-webdriver/src/aws-device-farm.test.ts‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from 'node:assert/strict';
2-
import { test } from 'vitest';
2+
import { afterEach, test, vi } from 'vitest';
33
import type { DeviceLease } from '@agent-device/contracts/device';
44
import {
55
AppError,
@@ -15,6 +15,10 @@ import { buildCloudWebDriverBaseCapabilities } from './runtime.ts';
1515

1616
const ARN = 'arn:aws:devicefarm:us-west-2:1:session/pending';
1717

18+
afterEach(() => {
19+
vi.restoreAllMocks();
20+
});
21+
1822
// Once `create-remote-access-session` answers, the ARN is a billed session that
1923
// nothing else will stop. Every way the startup wait can end short of RUNNING
2024
// must stop it before the failure surfaces (#1774 ownership rule, one phase
@@ -75,6 +79,40 @@ test('the allocation deadline caps the startup wait below its own default', asyn
7579
assert.deepEqual(client.stopped, [ARN]);
7680
});
7781

82+
// Live iOS real devices needed ~128s to reach RUNNING while the daemon's 300s
83+
// allocation budget still had room, and the standalone 120s default cut them
84+
// off. When the daemon supplies a deadline it is THE bound; the default only
85+
// applies without one. Time is a virtual clock advanced 10s per poll, so this is
86+
// deterministic and fails on the old `min(default, deadline)` logic (which
87+
// throws at 120s, before the 150s RUNNING).
88+
test('the allocation deadline lets startup run past the standalone 120s default', async () => {
89+
const startedAt = 1_700_000_000_000;
90+
let virtualNow = startedAt;
91+
vi.spyOn(Date, 'now').mockImplementation(() => virtualNow);
92+
const client = fakeClient({ status: 'PENDING' }, () => {
93+
virtualNow += 10_000;
94+
if (virtualNow - startedAt >= 150_000) {
95+
client.session.status = 'RUNNING';
96+
client.session.endpoints = { appium: 'https://appium.example/wd/hub' };
97+
}
98+
});
99+
const prepare = createAwsDeviceFarmPrepareSession({
100+
...baseOptions(client),
101+
// The standalone default; a daemon-supplied deadline must override it.
102+
startupTimeoutMs: 120_000,
103+
pollIntervalMs: 1,
104+
});
105+
106+
const prepared = await prepare({
107+
lease: makeLease(),
108+
req: { deadline: startedAt + 300_000 },
109+
base: baseSession(),
110+
});
111+
assert.equal(prepared.providerSessionId, ARN);
112+
assert.ok(virtualNow - startedAt >= 150_000, 'RUNNING must have been observed after 120s');
113+
assert.deepEqual(client.stopped, []);
114+
});
115+
78116
test('a session that reaches RUNNING is handed on and not stopped', async () => {
79117
const client = fakeClient({
80118
status: 'RUNNING',
@@ -91,10 +129,11 @@ test('a session that reaches RUNNING is handed on and not stopped', async () =>
91129
function fakeClient(
92130
session: Partial<AwsDeviceFarmRemoteAccessSession>,
93131
onPoll?: () => void,
94-
): AwsDeviceFarmClient & { stopped: string[] } {
132+
): AwsDeviceFarmClient & { stopped: string[]; session: Partial<AwsDeviceFarmRemoteAccessSession> } {
95133
const stopped: string[] = [];
96134
return {
97135
stopped,
136+
session,
98137
createRemoteAccessSession: async () => ({ arn: ARN, status: 'PENDING' }),
99138
getRemoteAccessSession: async (arn) => {
100139
onPoll?.();

0 commit comments

Comments
 (0)