Skip to content

Commit

Permalink
Remove Promise.race() in e2e test (#2365)
Browse files Browse the repository at this point in the history
This PR refactors the e2e tests to not use `Promise.race`. This 
`Promise.race` is problematic because one of the Promises keeps
polling the chromedriver until the timeout is reached.

The observed flakiness of the 
"Register with PIN then log into client application"
test (due to chromedriver becoming unresponsive, presumably crashing)
during polling when waiting for auth to finish seems to be reduced with
this change.
  • Loading branch information
frederikrothenberger committed Mar 15, 2024
1 parent 6c34591 commit c689ce8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 46 deletions.
43 changes: 3 additions & 40 deletions src/frontend/src/test-e2e/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,56 +104,19 @@ export const FLOWS = {
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(deviceName);
},

// A PIN auth view that's allowed to fail
loginPinAuthenticateView_: async (
loginPinAuthenticateView: async (
userNumber: string,
pin: string,
browser: WebdriverIO.Browser
): Promise<"ok" | "pin_disallowed"> => {
): Promise<void> => {
const authenticateView = new AuthenticateView(browser);
await authenticateView.waitForDisplay();
await authenticateView.pickAnchor(userNumber);
const pinAuthView = new PinAuthView(browser);
// Here we race two things:
// * The PIN authn view
// * Expecting an error because PIN is not allowed
// If the PIN authn view is returned then carry forward;
// otherwise return that PIN is not allowed
const result = await Promise.race([
pinAuthView.waitForDisplay().then(() => "pin_allowed" as const),
browser
.$('#errorContainer [data-error-code="pinNotAllowed"]')
.waitForDisplayed()
.then(() => "pin_disallowed" as const),
]);
if (result === "pin_disallowed") {
return "pin_disallowed";
}
result satisfies "pin_allowed";

await pinAuthView.waitForDisplay();
await pinAuthView.enterPin(pin);
// This flow assumes no recovery phrase, so we explicitly skip the recovery nag here
await FLOWS.skipRecoveryNag(browser);
return "ok";
},
loginPinAuthenticateView: async (
userNumber: string,
pin: string,
browser: WebdriverIO.Browser
): Promise<void> => {
const result = await FLOWS.loginPinAuthenticateView_(
userNumber,
pin,
browser
);
if (result === "pin_disallowed") {
throw new Error(
"Expected successful pin authentication, got PIN disallowed"
);
}

result satisfies "ok";
},
loginPinWelcomeView: async (
userNumber: string,
Expand Down
12 changes: 6 additions & 6 deletions src/frontend/src/test-e2e/pinAuthDisabled.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ test("Cannot auth with PIN if dapp disallows PIN", async () => {

await switchToPopup(browser);

const result = await FLOWS.loginPinAuthenticateView_(
userNumber,
pin,
browser
);
expect(result).toBe("pin_disallowed");
const authenticateView = new AuthenticateView(browser);
await authenticateView.waitForDisplay();
await authenticateView.pickAnchor(userNumber);
await browser
.$('#errorContainer [data-error-code="pinNotAllowed"]')
.waitForDisplayed();
}, APPLE_USER_AGENT);
}, 300_000);

0 comments on commit c689ce8

Please sign in to comment.