Skip to content

Eliminate use of StopRun(true) - #1858

Merged
CharliePoole merged 4 commits into
mainfrom
issue-1856
Jul 31, 2026
Merged

Eliminate use of StopRun(true)#1858
CharliePoole merged 4 commits into
mainfrom
issue-1856

Conversation

@CharliePoole

Copy link
Copy Markdown
Member

Eliminates use of StopRun(bool) in the engine and agent core and fixes #1856.

StopRun(false) is replaced by RequestStop(), which is intended to make it clear that the test may not stop. The caller may only request it and the result depends on the test framework, possibly its version and the test code itself.

StopRun(true) is replace by ForcedStop(). If the test framework provides any facilities for such a stop, they are used. Otherwise, any non terminated processes are canceled by the engine.

The initial commit makes the necessary replacements but code to kill agent processes is not yet implemented.

@CharliePoole
CharliePoole marked this pull request as draft July 28, 2026 20:20
@CharliePoole

Copy link
Copy Markdown
Member Author

@manfred-brands
I'm keeping this as a draft until a few things are resolved...

  1. I'd like to see how you resolve Eliminate forced stop from the API nunit#5373 and accommodate the engine fix to whatever you do in the driver code.
  2. Deciding whether to Kill test processes from the engine in response to a forced stop and, if so, where to do it.
  3. Deciding whether to continue to fabricate TestSuite results in the engine after a forced stop or to expect clients (runners) to deal with it. In the PR, that code is currently removed using conditional compilation, so we can test the adapter with it.

It would be be useful if you'd take a look at the PR as it is now and let me know what you think.

@manfred-brands

Copy link
Copy Markdown
Member
  1. I'd like to see how you resolve Eliminate forced stop from the API nunit#5373 and accommodate the engine fix to whatever you do in the driver code.

I have raised nunit/nunit#5374

I left the signature for the FrameworkController the same (similar what you did earlier).
That way existing runners should still work (unless they set force to true)

@CharliePoole

Copy link
Copy Markdown
Member Author

On the other items...

  1. Deciding whether to Kill test processes from the engine in response to a forced stop and, if so, where to do it.

I'll have the agent just terminate itself when it receives a ForcedStop() call.

  1. Deciding whether to continue to fabricate TestSuite results in the engine after a forced stop or to expect clients (runners) to deal with it. In the PR, that code is currently removed using conditional compilation, so we can test the adapter with it.

For now, I'm going to turn the tracker code back on.

@CharliePoole
CharliePoole marked this pull request as ready for review July 30, 2026 14:48
@CharliePoole

Copy link
Copy Markdown
Member Author

@manfred-brands This is ready for review. I've left a few things for a later issue/PR...

  1. Somebody up the hierarchy should probably wait to see if the job was cancelled. This is hard to test under the console runner. My GUI has menu options for Stop and Kill, so I'll test it there once it's using the latest NUnit code. I'm thinking that the best place for this is probably in each runner, but we'll see.
  2. Right now, I'm guessing a bit about what will be in the final 5.0 release of the framework, so changes may be needed when that comes out.

@manfred-brands manfred-brands left a comment

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.

A few small suggestions.


[Test]
public void StopRun_Throws_NUnitEngineException()
public void StopRun_Throws_ArgumentException()

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.

This method is looks identical to StopRun_Passes_Along_NUnitEngineException.
Proofing that _runner.ForcedStop() calls _driver.ForcedStop()

ID = id;
_nunitVersion = nunitRef.Version.ShouldNotBeNull();

if (nunitRef.Version >= MINIMUM_NUNIT_VERSION)

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.

Can use the new field.

Suggested change
if (nunitRef.Version >= MINIMUM_NUNIT_VERSION)
if (_nunitVersion >= MINIMUM_NUNIT_VERSION)

if (_api.ForcedStopSupported)
_api.ForcedStop();
else
Process.GetCurrentProcess().Kill();

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.

Is that not the same as calling Exit?

Suggested change
Process.GetCurrentProcess().Kill();
Environment.Exit(1);

@CharliePoole

Copy link
Copy Markdown
Member Author

Thanks. Good suggestions. I'll put them in and merge in the morning.

@CharliePoole
CharliePoole merged commit 0672e90 into main Jul 31, 2026
3 checks passed
@CharliePoole
CharliePoole deleted the issue-1856 branch July 31, 2026 16:38
@CharliePoole

Copy link
Copy Markdown
Member Author

@manfred-brands FYI, added a new exit code for the agent, CANCELLED_BY_FORCED_STOP = -6;

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.

Eliminate forced stop from the API

2 participants