Skip to content
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

🐛(frontend) improve e2e tests avoiding race condition from mocks #641

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Morendil
Copy link
Collaborator

@Morendil Morendil commented Jan 16, 2025

Purpose

Several E2E tests were suffering from a race condition problem. The race condition affected setting up mocked API calls with page.route and navigation to the front page of Desk. Specifically, the call to page.goto('/') was made before the call to page.route, without caring to synchronize the two. This meant that, at random, we could possibly have the API calls made by the front page complete before the mocks were in place, leading to a test failure.

Proposal

This PR aims to eliminate this source of intermittent CI failures, which are always obnoxious and lead to a waste of time (when we investigate why the build failed), of resources (when we have to rerun jobs) and more importantly a loss of confidence in the test suite.

We systematically have the calls to page.route take place (synchronously, with an await) before calling page.goto('/'). (Unfortunately this means that we cannot make use of test.beforeEach in these tests, a price I'm happy to pay as these clauses were only a couple lines each).

(There is one exception to this "rule", menu-spec.ts, because the login flow is triggered by a call to the /users/me endpoint, which must return a 401 on the first invocation; setting up the mock before the call to page.goto('/') interferes with that. We must trigger the login process by loading the home page, then prepare the mock, then proceed with login. Unfortunately I'm not able to find a fix for this that works both locally and in CI, so I'm leaving menu-spec.ts unchanged for now.)

In addition, fix some E2E calls that were not making use of await, to be more in line with all other E2E tests.

In addition, lower the default timeout for Playwright tests to 10 seconds, which is plenty.

@Morendil Morendil force-pushed the lbo/fix-e2e-race-conditions branch 2 times, most recently from b9bd04f to 3bcddeb Compare January 16, 2025 12:45
@Morendil Morendil marked this pull request as ready for review January 16, 2025 12:45
@Morendil Morendil force-pushed the lbo/fix-e2e-race-conditions branch from 3bcddeb to 0aa926d Compare January 16, 2025 13:13
@@ -164,6 +166,10 @@ test.describe('Mail domains', () => {
});
});

await page.goto('/');
// See comment above
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vaudrait mieux être explicite à chaque fois non ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reorder mock setup with page.route so that it takes place before nav.
@Morendil Morendil force-pushed the lbo/fix-e2e-race-conditions branch from 0aa926d to 7c34431 Compare January 18, 2025 22:33
@Morendil Morendil requested a review from sdemagny January 20, 2025 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants