Skip to content

Commit 3e0a5ca

Browse files
fix(vscode): retry temp directory cleanup in the e2e fixture (#6094)
Signed-off-by: Adegbite Ayoade <tripleaceme@gmail.com> Co-authored-by: Cortland Goffena <30168413+cmgoffena13@users.noreply.github.com>
1 parent 92e9514 commit 3e0a5ca

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

‎vscode/extension/tests/fixtures.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,33 @@ import {
88
CodeServerContext,
99
} from './utils_code_server'
1010

11+
const REMOVE_RETRY_DELAYS_MS = [100, 250, 500, 1000, 2000]
12+
13+
/**
14+
* Remove a directory, retrying with a backoff.
15+
*
16+
* When a test finishes, the extension host may still be writing into its
17+
* temporary directory - the language server is shutting down, or uv is
18+
* finishing off a virtual environment it created there. A single `fs.remove`
19+
* then fails with `ENOTEMPTY`, which fails an otherwise passing test.
20+
*/
21+
const removeWithRetry = async (dir: string): Promise<void> => {
22+
for (let attempt = 0; ; attempt++) {
23+
try {
24+
await fs.remove(dir)
25+
return
26+
} catch (error) {
27+
if (attempt >= REMOVE_RETRY_DELAYS_MS.length) {
28+
console.warn(`Failed to remove directory ${dir}:`, error)
29+
return
30+
}
31+
await new Promise(resolve =>
32+
setTimeout(resolve, REMOVE_RETRY_DELAYS_MS[attempt]),
33+
)
34+
}
35+
}
36+
}
37+
1138
// Worker-scoped fixture to start/stop VS Code server once per worker
1239
export const test = base.extend<
1340
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
@@ -52,7 +79,7 @@ export const test = base.extend<
5279

5380
// Clean up after each test
5481
console.log(`Cleaning up temporary directory: ${tempDir}`)
55-
await fs.remove(tempDir)
82+
await removeWithRetry(tempDir)
5683
},
5784
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5885
// @ts-expect-error

0 commit comments

Comments
 (0)