Skip to content

Commit 0753de5

Browse files
committed
test(e2e): retry dataset downloads in onPrepare
Flaky connectivity to data.kitware.com could fail a single onPrepare download, leaving .tmp without the dataset and causing specs to fail at the render-wait step as if WebGL were broken. Retry each download up to 3 times, write atomically via a .part rename so a partial download is never cached as complete, and check response.ok so an error page is not saved as DICOM.
1 parent a66d1cf commit 0753de5

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

wdio.shared.conf.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,45 @@ export const config: Options.Testrunner = {
111111
async onPrepare() {
112112
fs.mkdirSync(TEMP_DIR, { recursive: true });
113113

114+
const RETRIES = 3;
115+
const RETRY_DELAY_MS = 500;
116+
const delay = (ms: number) =>
117+
new Promise((resolve) => {
118+
setTimeout(resolve, ms);
119+
});
120+
const downloadOnce = async (url: string, savePath: string) => {
121+
const response = await fetch(url);
122+
if (!response.ok) {
123+
throw new Error(`HTTP ${response.status} for ${url}`);
124+
}
125+
const data = await response.arrayBuffer();
126+
// Write to a temp path first so a failed/partial download never leaves a
127+
// corrupt file that the existsSync check would treat as already cached.
128+
const tmpPath = `${savePath}.part`;
129+
fs.writeFileSync(tmpPath, Buffer.from(data));
130+
fs.renameSync(tmpPath, savePath);
131+
};
132+
114133
const downloads = TEST_DATASETS.map(async ({ url, name }) => {
115134
const savePath = path.join(TEMP_DIR, name);
116135
if (fs.existsSync(savePath)) {
117136
return;
118137
}
119-
const response = await fetch(url);
120-
const data = await response.arrayBuffer();
121-
fs.writeFileSync(savePath, Buffer.from(data));
138+
for (let attempt = 1; attempt <= RETRIES; attempt += 1) {
139+
try {
140+
await downloadOnce(url, savePath);
141+
return;
142+
} catch (err) {
143+
if (attempt === RETRIES) {
144+
throw new Error(
145+
`Failed to download ${name} after ${RETRIES} attempts: ${
146+
(err as Error).message
147+
}`
148+
);
149+
}
150+
await delay(RETRY_DELAY_MS);
151+
}
152+
}
122153
});
123154
await Promise.all(downloads);
124155
},

0 commit comments

Comments
 (0)