Skip to content

Conversation

@manfred-brands
Copy link
Member

@manfred-brands manfred-brands commented May 6, 2023

Fixes #4385 #1821

This is a cooperative multitasking alternative to TimeoutAttribute

@manfred-brands manfred-brands force-pushed the feature/4385_CancelAfterAttribute branch from d966f35 to f1f1789 Compare May 6, 2023 08:42
@manfred-brands manfred-brands marked this pull request as draft May 6, 2023 09:25
@manfred-brands
Copy link
Member Author

Convert to draft to see why the Unix based build were hanging.

@manfred-brands manfred-brands force-pushed the feature/4385_CancelAfterAttribute branch from f1f1789 to 9667f43 Compare June 13, 2023 08:44
This is a cooperative multitasking alternative to TimeoutAttribute
@manfred-brands manfred-brands force-pushed the feature/4385_CancelAfterAttribute branch from 9667f43 to ecadfd6 Compare August 12, 2023 04:33
@manfred-brands manfred-brands marked this pull request as ready for review August 12, 2023 09:12
@manfred-brands
Copy link
Member Author

This introduces a new CancelAfter attribute.
The framework will automatically pass in an CancellatonToken argument if the test expects one, alternatively that is available under TestExecutionContext.CancellationToken

Note that this is cooperative and only works if test code (or code called from there) passes in and obeys this token.

@stevenaw
Copy link
Member

Congrats on finding the underlying linux issue @manfred-brands . I'll try to take a look within the week

{
// Because of the debugger possibly attaching after the test method is started
// we use a 2-prong approach where we only cancel the test's cancellation token
// if the debugger is not attached when the timer expires.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding this. Good thinking to have this caveat about the debugger

public void InfiniteLoopWith50msTimeout()
{
while (true) { }
Thread.Sleep(5000);
Copy link
Member

Choose a reason for hiding this comment

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

👍 thank you for this update too

Copy link
Member

Choose a reason for hiding this comment

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

nitpick: Actually, I feel like this may no longer do what the test method name says. Is it worth keeping keeping one busy wait in place to simulate a CPU-bound long running test?

Copy link
Member Author

Choose a reason for hiding this comment

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

I mainly made this change to prevent the builds hanging and taking up unnecessary resources.
Yes, they probably should be renamed.
I don't see a point in making a CPU-bound versions. It should not make a difference in 'interuptability'.

{
Assert.That(value, Is.EqualTo(1));
Assert.That(cancellationToken, Is.Not.EqualTo(CancellationToken.None));
Assert.That(cancellationToken, Is.EqualTo(TestContext.CurrentContext.CancellationToken));
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

@stevenaw stevenaw left a comment

Choose a reason for hiding this comment

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

Thanks @manfred-brands nicely done getting this working. This looks good to me at first glance, though there is enough here and I am sleepy enough that I would appreciate a second pair of eyes from either myself later or another team member.

@OsirisTerje or @jnm2 Are either of you are up to a review?

@manfred-brands
Copy link
Member Author

ping @nunit/framework-team Any one else for a 2nd review?

@OsirisTerje
Copy link
Member

@manfred-brands There are a lot of changes/additions here. I can't really wrap my brain around it. Is there anything in particular in the code you're worried about?

@manfred-brands
Copy link
Member Author

@manfred-brands There are a lot of changes/additions here. I can't really wrap my brain around it. Is there anything in particular in the code you're worried about?

@OsirisTerje Not really worried, but could you look at the changes to TestResult.cs and SimpleWorkItem.cs as they deal with existing code.

@manfred-brands
Copy link
Member Author

@nunit/framework-team Does anyone has any objections to me merging this?

@OsirisTerje
Copy link
Member

Suggest you just merge it, and then we check the dev build afterwards. I could not see anything that raised any worries here.

Copy link
Member

@OsirisTerje OsirisTerje left a comment

Choose a reason for hiding this comment

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

LGTM

@manfred-brands manfred-brands merged commit 77c281b into nunit:master Sep 27, 2023
@manfred-brands manfred-brands deleted the feature/4385_CancelAfterAttribute branch September 27, 2023 09: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.

Add support for Test Cancellation

3 participants