Address a flaky spec by waiting (#17385)

We had seen an increase in CI timeouts (no output received for 10
minutes).

Running this example (signed out user sees the pinned article)
repeatedly I was able to reproduce the failure seen in Travis, and
checking the last few times this occurred it appears to be linked to
the pinArticle.spec.js last test, which fails with an
ApplicationPolicy when pinning.

The likeliest source of this issue is the POST (pin the article) is
received concurrently with the session delete (logging the admin user
out), resulting in a race. If/when the signout occurs before the
article policy is checked (does the current user have permission to
pin an article), the cypress running stalls.

This occurred both interactively (bin/e2e or cypress open) and
headless (cypress run/CI). The error went away reliably after
inserting this guard to check for the "Unpin post" link on the page,
which forces the POST to have completed and redirected back to the
admin page before logging out.

My understanding of this problem is borne out in the local test logs,
where the signout and pin requests arrive concurrently and process out
of order (and the POST gives a 404 instead of a 302).

    Started DELETE "/users/sign_out" for 127.0.0.1 at 2022-04-20 12:09:23 -0500
    Started POST "/admin/content_manager/articles/1/pin" for 127.0.0.1 at 2022-04-20 12:09:23 -0500
    Completed 204 No Content in 42ms (ActiveRecord: 6.2ms | Allocations: 6323)
    Completed 404 Not Found in 4ms (ActiveRecord: 0.4ms | Allocations: 833)
This commit is contained in:
Daniel Uber 2022-04-21 09:18:08 -05:00 committed by GitHub
parent 8fbc2e86d5
commit f6a648c607
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -97,6 +97,7 @@ describe('Pin an article from the admin area', () => {
it('should show the pinned post to a logged out user', () => {
cy.findAllByRole('button', { name: 'Pin post' }).first().click();
cy.findByRole('link', { name: 'Unpin post' }).should('exist');
cy.signOutUser();
cy.findByRole('main').findByTestId('pinned-article').should('be.visible');