test: fix flaky tests
This commit is contained in:
parent
a8a6ae24a9
commit
e20997748e
5 changed files with 43 additions and 53 deletions
|
|
@ -2,7 +2,7 @@ import { expect } from "chai";
|
|||
import { WebElement } from "vscode-extension-tester";
|
||||
|
||||
export class TestUtils {
|
||||
public static async waitForElement<T>(
|
||||
public static async waitForSuccess<T>(
|
||||
locatorFn: () => Promise<T>,
|
||||
timeout: number = 5000,
|
||||
interval: number = 500,
|
||||
|
|
@ -11,10 +11,8 @@ export class TestUtils {
|
|||
|
||||
while (Date.now() - startTime < timeout) {
|
||||
try {
|
||||
const element = await locatorFn();
|
||||
if (element) {
|
||||
return element;
|
||||
}
|
||||
const result = await locatorFn();
|
||||
return result;
|
||||
} catch (e) {
|
||||
if (Date.now() - startTime >= timeout) {
|
||||
throw new Error(`Element not found after ${timeout}ms timeout`);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export class AutocompleteActions {
|
|||
const messagePair0 = TestUtils.generateTestMessagePair(0);
|
||||
await editor.typeTextAt(1, 1, messagePair0.userMessage);
|
||||
await editor.typeTextAt(1, messagePair0.userMessage.length + 1, " ");
|
||||
const ghostText0 = await TestUtils.waitForElement(
|
||||
const ghostText0 = await TestUtils.waitForSuccess(
|
||||
() => AutocompleteSelectors.getGhostTextContent(driver),
|
||||
// The first completion takes longer because Continue needs to load
|
||||
DEFAULT_TIMEOUT,
|
||||
|
|
@ -24,7 +24,7 @@ export class AutocompleteActions {
|
|||
const messagePair1 = TestUtils.generateTestMessagePair(1);
|
||||
await editor.typeTextAt(1, 1, messagePair1.userMessage);
|
||||
await editor.typeTextAt(1, messagePair1.userMessage.length + 1, " ");
|
||||
const ghostText1 = await TestUtils.waitForElement(() =>
|
||||
const ghostText1 = await TestUtils.waitForSuccess(() =>
|
||||
AutocompleteSelectors.getGhostTextContent(driver),
|
||||
);
|
||||
expect(ghostText1).to.equal(messagePair1.llmResponse);
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ export class GUIActions {
|
|||
const dropdownButton = await GUISelectors.getModelDropdownButton(view);
|
||||
await dropdownButton.click();
|
||||
|
||||
const dropdownOption = await TestUtils.waitForElement(() => {
|
||||
const dropdownOption = await TestUtils.waitForSuccess(() => {
|
||||
return GUISelectors.getModelDropdownOption(view, option);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ describe("GUI Test", () => {
|
|||
const messagePair = TestUtils.generateTestMessagePair();
|
||||
await messageInput.sendKeys(messagePair.userMessage);
|
||||
await messageInput.sendKeys(Key.ENTER);
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, messagePair.llmResponse),
|
||||
);
|
||||
});
|
||||
|
|
@ -64,7 +64,7 @@ describe("GUI Test", () => {
|
|||
const messagePair = TestUtils.generateTestMessagePair();
|
||||
await messageInput.sendKeys(messagePair.userMessage);
|
||||
(await GUISelectors.getSubmitInputButton(view)).click();
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, messagePair.llmResponse),
|
||||
);
|
||||
});
|
||||
|
|
@ -77,7 +77,7 @@ describe("GUI Test", () => {
|
|||
message: userMessage0,
|
||||
inputFieldIndex: 0,
|
||||
});
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, llmResponse0),
|
||||
);
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ describe("GUI Test", () => {
|
|||
message: userMessage1,
|
||||
inputFieldIndex: 1,
|
||||
});
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, llmResponse1),
|
||||
);
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ describe("GUI Test", () => {
|
|||
message: userMessage2,
|
||||
inputFieldIndex: 2,
|
||||
});
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, llmResponse2),
|
||||
);
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ describe("GUI Test", () => {
|
|||
message: userMessage0,
|
||||
inputFieldIndex: 0,
|
||||
});
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, llmResponse0),
|
||||
);
|
||||
|
||||
|
|
@ -141,7 +141,7 @@ describe("GUI Test", () => {
|
|||
message: userMessage1,
|
||||
inputFieldIndex: 1,
|
||||
});
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, llmResponse1),
|
||||
);
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ describe("GUI Test", () => {
|
|||
message: userMessage2,
|
||||
inputFieldIndex: 2,
|
||||
});
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, llmResponse2),
|
||||
);
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ describe("GUI Test", () => {
|
|||
});
|
||||
await GUISelectors.getThreadMessageByText(view, llmResponse0);
|
||||
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, llmResponse3),
|
||||
);
|
||||
await Promise.all([
|
||||
|
|
@ -194,7 +194,7 @@ describe("GUI Test", () => {
|
|||
message: messagePair1.userMessage,
|
||||
inputFieldIndex: 0,
|
||||
});
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, messagePair1.llmResponse),
|
||||
);
|
||||
|
||||
|
|
@ -204,7 +204,7 @@ describe("GUI Test", () => {
|
|||
message: messagePair2.userMessage,
|
||||
inputFieldIndex: 1,
|
||||
});
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, messagePair2.llmResponse),
|
||||
);
|
||||
|
||||
|
|
@ -238,7 +238,7 @@ describe("GUI Test", () => {
|
|||
message: messagePair3.userMessage,
|
||||
inputFieldIndex: 2,
|
||||
});
|
||||
await TestUtils.waitForElement(() =>
|
||||
await TestUtils.waitForSuccess(() =>
|
||||
GUISelectors.getThreadMessageByText(view, messagePair3.llmResponse),
|
||||
);
|
||||
}).timeout(DEFAULT_TIMEOUT);
|
||||
|
|
|
|||
|
|
@ -3,12 +3,15 @@ import {
|
|||
TextEditor,
|
||||
InputBox,
|
||||
Workbench,
|
||||
VSBrowser,
|
||||
Key,
|
||||
} from "vscode-extension-tester";
|
||||
|
||||
import { DEFAULT_TIMEOUT } from "../constants";
|
||||
import { TestUtils } from "../TestUtils";
|
||||
import { SSHSelectors } from "../selectors/SSH.selectors";
|
||||
import { AutocompleteActions } from "../actions/Autocomplete.actions";
|
||||
import * as path from "path";
|
||||
|
||||
describe("SSH", function () {
|
||||
this.retries(2); // Retries failed tests up to 2 times
|
||||
|
|
@ -19,49 +22,38 @@ describe("SSH", function () {
|
|||
await new Workbench().executeCommand(
|
||||
"Remote-SSH: Connect Current Window to Host...",
|
||||
);
|
||||
await (await InputBox.create()).selectQuickPick("ssh-test-container");
|
||||
await (
|
||||
await InputBox.create(DEFAULT_TIMEOUT)
|
||||
).selectQuickPick("ssh-test-container");
|
||||
|
||||
await TestUtils.waitForElement(
|
||||
await TestUtils.waitForSuccess(
|
||||
() => SSHSelectors.connectedToRemoteConfirmationMessage(),
|
||||
DEFAULT_TIMEOUT,
|
||||
);
|
||||
|
||||
await new Promise((res) => {
|
||||
setTimeout(res, 1000);
|
||||
});
|
||||
await TestUtils.waitForSuccess(async () => {
|
||||
await new Workbench().executeCommand("File: Open Folder...");
|
||||
const inputBox = await InputBox.create(DEFAULT_TIMEOUT);
|
||||
await inputBox.setText("/home/ec2-user/test-folder");
|
||||
await inputBox.confirm();
|
||||
}, DEFAULT_TIMEOUT);
|
||||
|
||||
await new Workbench().executeCommand("File: Open Folder...");
|
||||
await new Promise((res) => {
|
||||
setTimeout(res, 4000);
|
||||
});
|
||||
|
||||
const inputBox = await TestUtils.waitForElement(
|
||||
() => InputBox.create(),
|
||||
DEFAULT_TIMEOUT,
|
||||
);
|
||||
await inputBox.selectQuickPick("test-folder");
|
||||
await new Promise((res) => {
|
||||
setTimeout(res, 4000);
|
||||
});
|
||||
await inputBox.confirm();
|
||||
|
||||
await new Promise((res) => {
|
||||
setTimeout(res, 4000);
|
||||
});
|
||||
|
||||
await new Workbench().executeCommand("File: Open File...");
|
||||
await (await InputBox.create(5000)).selectQuickPick("main.py");
|
||||
await new Promise((res) => {
|
||||
setTimeout(res, 4000);
|
||||
});
|
||||
await TestUtils.waitForSuccess(async () => {
|
||||
await new Workbench().executeCommand("File: Open File...");
|
||||
const inputBox = await InputBox.create(DEFAULT_TIMEOUT);
|
||||
await inputBox.setText("/home/ec2-user/test-folder/main.py");
|
||||
await inputBox.selectQuickPick("main.py");
|
||||
await inputBox.sendKeys(Key.ENTER);
|
||||
}, DEFAULT_TIMEOUT);
|
||||
});
|
||||
|
||||
it("Should display completions", async () => {
|
||||
const editor = (await new EditorView().openEditor("main.py")) as TextEditor;
|
||||
const editor = await TestUtils.waitForSuccess(
|
||||
async () => (await new EditorView().openEditor("main.py")) as TextEditor,
|
||||
DEFAULT_TIMEOUT,
|
||||
);
|
||||
|
||||
await editor.clearText();
|
||||
await AutocompleteActions.testCompletions(editor);
|
||||
// await new Promise((res) => {
|
||||
// setTimeout(res, DEFAULT_TIMEOUT);
|
||||
// });
|
||||
}).timeout(DEFAULT_TIMEOUT);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue