Skip to content

Commit

Permalink
E2E Utils: Add retry mechanism to the REST API discovery (#62331)
Browse files Browse the repository at this point in the history
Co-authored-by: WunderBart <bartkalisz@git.wordpress.org>
Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: GraemeF <graemef@git.wordpress.org>
  • Loading branch information
6 people committed Jun 5, 2024
1 parent 0d1943c commit 8d15c5f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
31 changes: 27 additions & 4 deletions packages/e2e-test-utils-playwright/src/request-utils/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import * as fs from 'fs/promises';
import { dirname } from 'path';
import { expect } from '@playwright/test';
import type { APIRequestContext } from '@playwright/test';

/**
Expand Down Expand Up @@ -39,10 +40,32 @@ async function getAPIRootURL( request: APIRequestContext ) {
}

async function setupRest( this: RequestUtils ): Promise< StorageState > {
const [ nonce, rootURL ] = await Promise.all( [
this.login(),
getAPIRootURL( this.request ),
] );
let nonce = '';
let rootURL = '';

// Poll until the REST API is discovered.
// See https://github.com/WordPress/gutenberg/issues/61627
await expect
.poll(
async () => {
try {
[ nonce, rootURL ] = await Promise.all( [
this.login(),
getAPIRootURL( this.request ),
] );
} catch ( error ) {
// Prints the error if the timeout is reached.
return error;
}

return nonce && rootURL ? true : false;
},
{
message: 'Failed to setup REST API.',
timeout: 60_000, // 1 minute.
}
)
.toBe( true );

const { cookies } = await this.request.storageState();

Expand Down
4 changes: 1 addition & 3 deletions test/performance/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ process.env.ASSETS_PATH = path.join( __dirname, 'assets' );

const config = defineConfig( {
...baseConfig,
reporter: process.env.CI
? './config/performance-reporter.ts'
: [ [ 'list' ], [ './config/performance-reporter.ts' ] ],
reporter: [ [ 'list' ], [ './config/performance-reporter.ts' ] ],
forbidOnly: !! process.env.CI,
fullyParallel: false,
retries: 0,
Expand Down

1 comment on commit 8d15c5f

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 8d15c5f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9388197120
📝 Reported issues:

Please sign in to comment.