Skip to content

Exponential test sleep backoff #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/test/suite/recorded.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ suite("recorded test cases", async function () {
excludeFields.push("clipboard");
}

// Wait for cursorless to set up decorations
cursorlessApi.addDecorations();

// Assert that recorded decorations are present
const assertDecorations = () => {
// Wait for cursorless to set up decorations
cursorlessApi.addDecorations();

Object.entries(fixture.marks).forEach(([key, token]) => {
const { color, character } = NavigationMap.splitKey(key);
const currentToken = cursorlessApi.navigationMap.getToken(
Expand All @@ -125,7 +125,7 @@ suite("recorded test cases", async function () {
};

// Tried three times, sleep 100ms between each
await tryAndRetry(assertDecorations, 3, 100);
await tryAndRetry(assertDecorations, 6, 50);

const returnValue = await vscode.commands.executeCommand(
"cursorless.command",
Expand Down Expand Up @@ -160,18 +160,20 @@ suite("recorded test cases", async function () {

async function tryAndRetry(
callback: () => void,
numberOfThries: number,
sleepTime: number
numberOfTries: number,
initialSleepTime: number
) {
var sleepTime = initialSleepTime;
while (true) {
try {
return callback();
} catch (error) {
if (numberOfThries === 0) {
if (numberOfTries === 0) {
throw error;
}
numberOfThries--;
numberOfTries--;
await new Promise((resolve) => setTimeout(resolve, sleepTime));
sleepTime *= 2;
}
}
}