Skip to content
Prev Previous commit
Next Next commit
retry API discovery along with login
  • Loading branch information
WunderBart committed Jun 5, 2024
commit 60bf4114e71d5daccda49c38f4b5787167c50b70
29 changes: 25 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,30 @@ 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 = '';

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.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Do we have a rough number when the REST API will be available? A minute seems like a long wait if it returns nothing. Is 5 seconds or 10 seconds enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question, and I have no idea TBH. Testing this thing takes ages, and it only fails in CI. Having said that, since this solution seems to be working across the board, I can lower the timeout value and do a couple more reruns. We can also address it in a follow-up PR since the failing perf tests keep blocking folks. What do you think?

}
)
.toBe( true );

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

Expand Down