Skip to content

Commit 91d68a4

Browse files
hasufellfendor
authored andcommitted
Retry promise in CI test
1 parent c4ae6b4 commit 91d68a4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/suite/extension.test.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ async function withTimeout(seconds: number, f: Promise<any>) {
1818
return Promise.race([f, delay(seconds)]);
1919
}
2020

21+
const wait = (ms: number) => new Promise(r => setTimeout(r, ms));
22+
23+
const retryOperation = (operation: () => Promise<any>, delay: number, retries: number) => new Promise((resolve, reject): Promise<any> => {
24+
return operation()
25+
.then(resolve)
26+
.catch((reason) => {
27+
if (retries > 0) {
28+
return wait(delay)
29+
.then(retryOperation.bind(null, operation, delay, retries - 1))
30+
.then(resolve)
31+
.catch(reject);
32+
}
33+
return reject(reason);
34+
});
35+
});
36+
37+
2138
function getHaskellConfig() {
2239
return vscode.workspace.getConfiguration('haskell');
2340
}
@@ -165,7 +182,8 @@ suite('Extension Test Suite', () => {
165182
await delay(20);
166183
const logContents = getExtensionLogContent();
167184
assert.ok(logContents, 'Extension log file does not exist');
168-
assert.match(logContents, /INFO hls:\s+Registering ide configuration/, 'Extension log file has no hls output');
185+
assert.ok(retryOperation(() => new Promise((resolve, reject) => (logContents.match(/INFO hls:\s+Registering ide configuration/) !== null) ? resolve : reject), 1000 * 5, 20),
186+
'Extension log file has no hls output');
169187
});
170188

171189
test('Server should inherit environment variables defined in the settings', async () => {

0 commit comments

Comments
 (0)