Skip to content

chore: make retries work with custom timeouts - #2319

Closed
Max Schmitt (mxschmitt) wants to merge 6 commits into
microsoft:mainfrom
mxschmitt:custom-timeout-handling
Closed

Max Schmitt (mxschmitt) wants to merge 6 commits into
microsoft:mainfrom
mxschmitt:custom-timeout-handling

Conversation

@mxschmitt

@mxschmitt Max Schmitt (mxschmitt) commented Sep 19, 2022 •

Copy link
Copy Markdown
Contributor

Differences between NUnit and MSTest:

  • NUnit will call the afterEach when a timeout is reached, this is not possible in MSTest since the base.Execute() takes care of calling beforeEach/afterEach.

Both implementations will:

  • throw if test framework timeout < Playwright test timeout
  • gracefully close the BrowserContext when the test timeout has reached
  • making reached timeouts compatible with retries

Relates #2316

@mxschmitt
Max Schmitt (mxschmitt) force-pushed the custom-timeout-handling branch 2 times, most recently from cc1f338 to 4e10690 Compare September 23, 2022 12:26
@mxschmitt
Max Schmitt (mxschmitt) marked this pull request as ready for review September 27, 2022 20:56

// 2.2 Wait for the test execution to complete (let e.g. Page.ClickAsync throw)
// and give the test 5 seconds to finish.
await Task.WhenAny(testExecutionTask, Task.Delay(5000));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Drop this one please.

{
foreach (var cleanupMethod in CleanupMethods)
{
await cleanupMethod();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So this only cleans up our context, but does not run other [TestCleanup] methods. Is there a way to do that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not, since base.Execute(testMethod) already executes the TestInitialize and TestCleanup internally, so we can only execute it twice which we want to prevent. That's the reason for this custom new disposable layer called CleanupMethods.

Comment thread src/Playwright.NUnit/TimeoutCommand.cs Resolved
Comment thread src/Playwright.NUnit/TimeoutCommand.cs Resolved
@mxschmitt
Max Schmitt (mxschmitt) force-pushed the custom-timeout-handling branch 4 times, most recently from 92848cd to 9993077 Compare September 29, 2022 11:19
// 2. Close the BrowserContext
if (ContextCloseHookOnTimeout != null)
{
await ContextCloseHookOnTimeout().ConfigureAwait(false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would be nice to see some kind of cancellation of the close hook, but maybe I am overthinking it.

public override TestResult[] Execute(ITestMethod testMethod)
{
var timeout = PlaywrightSettingsProvider.TestTimeout;
if (timeout == null || Debugger.IsAttached)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I get the intent of not timing out under debugger, but it makes it impossible to debug the timeout flow. It would be nice to have a ENV variable that you can set and make it go into the async flow. You will have to pump up your timeouts in the test if you want to be able to go step through it, but to me it looks useful when you are assisting someone with their issue related to timeouts.

But feel free to ignore my suggestions if you think feature creep is bigger issue than not being able to debug this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll follow-up.

Comment thread src/Playwright.NUnit/ContextTest.cs Outdated
public async Task ContextTearDown()
{
await Context.CloseAsync().ConfigureAwait(false);
Context = null!;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I could not find why this is done, and it seems a bit obscure to force break your nullability. Are you checking it for null somewhere, or are you just trying to get it garbage collected earlier?

@mxschmitt
Max Schmitt (mxschmitt) force-pushed the custom-timeout-handling branch 3 times, most recently from b8283b7 to 222a751 Compare November 8, 2022 22:59
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.

3 participants