Skip to content

Commit e10d266

Browse files
CoverRyanhdalsania
authored andcommitted
add retry logic
fix issues add retry to CI switch to Apache approved action switch to Apache approved action add timeout
1 parent 76800ee commit e10d266

5 files changed

Lines changed: 71 additions & 13 deletions

File tree

.github/workflows/CI.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,19 @@ jobs:
168168
run: yarn install --frozen-lockfile
169169

170170
- name: Runs tests - Linux
171-
run: xvfb-run -a yarn test
171+
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0
172+
with:
173+
max_attempts: 3
174+
timeout_minutes: 120
175+
command: xvfb-run -a yarn test
172176
if: runner.os == 'Linux'
173177

174178
- name: Runs tests - Windows/Mac
175-
run: yarn test
179+
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0
180+
with:
181+
max_attempts: 3
182+
timeout_minutes: 120
183+
command: yarn test
176184
if: runner.os != 'Linux'
177185

178186
- name: Check for Errors in macOS

.github/workflows/nightly.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,19 @@ jobs:
9696
run: yarn install --frozen-lockfile
9797

9898
- name: Runs tests - Linux
99-
run: xvfb-run -a yarn test
99+
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0
100+
with:
101+
max_attempts: 3
102+
timeout_minutes: 120
103+
command: xvfb-run -a yarn test
100104
if: runner.os == 'Linux'
101105

102106
- name: Runs tests - Windows/Mac
103-
run: yarn test
107+
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0
108+
with:
109+
max_attempts: 3
110+
timeout_minutes: 120
111+
command: yarn test
104112
if: runner.os != 'Linux'
105113

106114
- name: Check for Errors in macOS

src/tests/runTest.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ function resolveMacOSExecutable(executablePath: string): string {
5555
return executablePath
5656
}
5757

58+
async function downloadAndUnzipVSCodeRetry(
59+
testVsCodeVersion,
60+
retries = 5,
61+
delay = 4000
62+
): Promise<string | undefined> {
63+
let backoff = delay
64+
for (let i = 1; i <= retries; i++) {
65+
try {
66+
const vscodeExecutablePath =
67+
await downloadAndUnzipVSCode(testVsCodeVersion)
68+
return vscodeExecutablePath
69+
} catch (error) {
70+
if (i === retries) {
71+
throw error
72+
} else {
73+
console.warn(`Attempt ${i} failed. Retrying in ${backoff}ms...`)
74+
await new Promise((r) => setTimeout(r, backoff))
75+
backoff = backoff * 2
76+
}
77+
}
78+
}
79+
}
80+
5881
async function main() {
5982
const disable_cert_verification =
6083
process.argv.includes('-k') ||
@@ -80,13 +103,14 @@ async function main() {
80103
// Passed to --extensionTestsPath
81104
const extensionTestsPath = path.resolve(__dirname, './suite/index')
82105

106+
// Download VS Code and retry upon error
83107
const downloadedExecutablePath =
84-
await downloadAndUnzipVSCode(testVsCodeVersion)
108+
await downloadAndUnzipVSCodeRetry(testVsCodeVersion)
85109
const vscodeExecutablePath = resolveMacOSExecutable(
86-
downloadedExecutablePath
110+
downloadedExecutablePath!
87111
)
88112

89-
// Download VS Code, unzip it and run the integration tests
113+
// Run the integration tests
90114
const runTestsResult = await runTests({
91115
vscodeExecutablePath,
92116
extensionDevelopmentPath,

src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ export async function fetchRetry(
532532
`Failed request to ${url}: ${res.status} ${res.statusText}`
533533
)
534534
} else {
535+
console.warn(`Attempt ${i} failed. Retrying in ${backoff}ms...`)
535536
await new Promise((r) => setTimeout(r, backoff))
536537
backoff = backoff * 2
537538
}

vite.config.mjs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,23 @@ function copyDebuggerOutAfterBuild() {
9494
async function downloadAndExtract(title, url, targetDir) {
9595
console.log(pc.cyan(`\n▶ Starting download for ${title}...\n`))
9696

97-
const res = await fetch(url)
98-
if (!res.ok || !res.body) {
99-
throw new Error(
100-
`Failed to download ${url}: ${res.status} ${res.statusText}`
101-
)
97+
let res = undefined
98+
let backoff = 4000
99+
for (let i = 1; i <= 5; i++) {
100+
res = await fetch(url)
101+
if (!res.ok || !res.body) {
102+
if (i === 5) {
103+
throw new Error(
104+
`Failed to download ${url}: ${res.status} ${res.statusText}`
105+
)
106+
} else {
107+
console.warn(`Attempt ${i} failed. Retrying in ${backoff}ms...`)
108+
await new Promise((r) => setTimeout(r, backoff))
109+
backoff = backoff * 2
110+
}
111+
} else {
112+
break
113+
}
102114
}
103115

104116
const totalBytes = Number(res.headers.get('content-length')) || 0
@@ -245,7 +257,12 @@ export default defineConfig(({ mode }) => {
245257
input: {
246258
extension: path.resolve(__dirname, 'src/adapter/extension.ts'),
247259
},
248-
external: ['vscode', '@omega-edit/client', ...builtinModules, /^node:.*/],
260+
external: [
261+
'vscode',
262+
'@omega-edit/client',
263+
...builtinModules,
264+
/^node:.*/,
265+
],
249266
output: {
250267
entryFileNames: 'extension.js',
251268
format: 'cjs',

0 commit comments

Comments
 (0)