Skip to content

Commit 4db8a5e

Browse files
committed
test(android,harmonyos): cross the boot deadline and cover the command-line-tools root
Review follow-ups: make the still-booting poll actually overrun the boot deadline, and assert HARMONYOS_COMMAND_LINE_TOOLS contributes its derived toolchain directory to PATH.
1 parent 84700ba commit 4db8a5e

2 files changed

Lines changed: 30 additions & 15 deletions

File tree

‎packages/platform-android/src/__tests__/emulator-lifecycle.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ function bootPropFailure(stdout: string, stderr: string) {
110110
};
111111
}
112112

113+
/** A poll that keeps missing like a real booting device does, and actually burns wall-clock time. */
114+
function slowBootPropFailure(delayMs: number) {
115+
return async () => {
116+
await new Promise((resolve) => setTimeout(resolve, delayMs));
117+
return { stdout: '', stderr: '', exitCode: 1 };
118+
};
119+
}
120+
113121
async function expectBootFailure(
114122
timeoutMs: number,
115123
): Promise<{ code: string; message: string; details: Record<string, unknown> }> {
@@ -141,15 +149,18 @@ test('a boot poll against an offline device fails as an adb transport loss witho
141149
});
142150

143151
test('a still-booting device past its deadline reports an Android boot timeout', async () => {
144-
mockRunCmd.mockImplementation(bootPropFailure('', ''));
152+
// 80 ms per poll with a 50 ms retry cadence crosses the 150 ms deadline inside the second
153+
// poll, so the failure is a device that ran out of budget, not three fast poll misses.
154+
mockRunCmd.mockImplementation(slowBootPropFailure(80));
145155

146156
const failure = await expectBootFailure(150);
147157

148158
assert.equal(failure.code, 'COMMAND_FAILED');
149159
assert.equal(failure.message, 'Android device did not finish booting in time');
150160
assert.equal(failure.details.reason, 'ANDROID_BOOT_TIMEOUT');
151161
assert.equal(failure.details.timeoutMs, 150);
152-
assert.equal(typeof failure.details.elapsedMs, 'number');
162+
assert.equal(Number(failure.details.elapsedMs) >= 150, true);
163+
assert.equal(mockRunCmd.mock.calls.length, 2);
153164
// The classifier sees BOOT_COMMAND_FAILED from the still-booting throw; the caller must
154165
// normalize it to the timeout, not trust the raw classification.
155166
assert.notEqual(failure.details.reason, 'BOOT_COMMAND_FAILED');

‎packages/platform-harmonyos/src/__tests__/hdc.test.ts‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,46 @@ test('runHarmonyHdc forwards a binding abort signal to an in-flight HDC command'
6767
assert.equal(mockRunCmd.mock.calls[0]?.[2]?.signal, controller.signal);
6868
});
6969

70-
/** Creates `<root>/default/openharmony/toolchains/hdc` as an executable, like DevEco lays out. */
71-
async function seedToolchain(root: string): Promise<string> {
72-
const toolchains = path.join(root, 'default', 'openharmony', 'toolchains');
73-
await fs.mkdir(toolchains, { recursive: true });
74-
const hdc = path.join(toolchains, 'hdc');
70+
/** HDC_SDK_PATH names the toolchains directory itself, so `HDC_SDK_PATH/hdc` must exist. */
71+
async function seedDirectToolchain(root: string): Promise<string> {
72+
await fs.mkdir(root, { recursive: true });
73+
const hdc = path.join(root, 'hdc');
7574
await fs.writeFile(hdc, '#!/bin/sh\nexit 0\n', 'utf8');
7675
await fs.chmod(hdc, 0o755);
7776
return root;
7877
}
7978

80-
/** HDC_SDK_PATH names the toolchains directory itself, so `HDC_SDK_PATH/hdc` must exist. */
81-
async function seedDirectToolchain(root: string): Promise<string> {
82-
await fs.mkdir(root, { recursive: true });
83-
const hdc = path.join(root, 'hdc');
79+
/** DevEco's home joins `default/openharmony/toolchains`; the command-line-tools root adds `sdk` first. */
80+
async function seedNestedToolchain(root: string, ...segments: string[]): Promise<string> {
81+
const toolchains = path.join(root, ...segments, 'default', 'openharmony', 'toolchains');
82+
await fs.mkdir(toolchains, { recursive: true });
83+
const hdc = path.join(toolchains, 'hdc');
8484
await fs.writeFile(hdc, '#!/bin/sh\nexit 0\n', 'utf8');
8585
await fs.chmod(hdc, 0o755);
8686
return root;
8787
}
8888

8989
test('ensureHarmonyToolchainPathConfigured prepends every root holding an hdc binary', async () => {
9090
const hdcSdkRoot = await seedDirectToolchain(mkdtempForTestSync('agent-device-hdc-sdk-'));
91-
const devecoRoot = await seedToolchain(mkdtempForTestSync('agent-device-hdc-deveco-'));
92-
// A declared root without an hdc executable must not join PATH.
93-
const emptyRoot = mkdtempForTestSync('agent-device-hdc-empty-');
91+
const devecoRoot = await seedNestedToolchain(mkdtempForTestSync('agent-device-hdc-deveco-'));
92+
const cmdlineRoot = await seedNestedToolchain(
93+
mkdtempForTestSync('agent-device-hdc-cmdline-'),
94+
'sdk',
95+
);
9496

9597
const env: NodeJS.ProcessEnv = {
9698
PATH: '/usr/bin',
9799
HDC_SDK_PATH: hdcSdkRoot,
98100
DEVECO_SDK_HOME: devecoRoot,
99-
HARMONYOS_COMMAND_LINE_TOOLS: emptyRoot,
101+
HARMONYOS_COMMAND_LINE_TOOLS: cmdlineRoot,
100102
};
101103

102104
await ensureHarmonyToolchainPathConfigured(env);
103105

104106
assert.deepEqual((env.PATH ?? '').split(path.delimiter), [
105107
hdcSdkRoot,
106108
path.join(devecoRoot, 'default', 'openharmony', 'toolchains'),
109+
path.join(cmdlineRoot, 'sdk', 'default', 'openharmony', 'toolchains'),
107110
'/usr/bin',
108111
]);
109112
});
@@ -113,6 +116,7 @@ test('ensureHarmonyToolchainPathConfigured leaves PATH untouched when no root ho
113116
PATH: '/usr/bin',
114117
HDC_SDK_PATH: ' ',
115118
DEVECO_SDK_HOME: mkdtempForTestSync('agent-device-hdc-none-'),
119+
HARMONYOS_COMMAND_LINE_TOOLS: mkdtempForTestSync('agent-device-hdc-none-'),
116120
};
117121

118122
await ensureHarmonyToolchainPathConfigured(env);

0 commit comments

Comments
 (0)