Skip to content

Commit 143b430

Browse files
committed
Modify ITestEngineResult interface splitting StopRun into two methods
1 parent b2eeb5b commit 143b430

File tree

11 files changed

+121
-44
lines changed

11 files changed

+121
-44
lines changed

src/NUnitEngine/nunit.engine.core.tests/Runners/DirectTestRunnerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void StopRun_Passes_Along_NUnitEngineException()
108108
_driver.When(x => x.StopRun(Arg.Any<bool>()))
109109
.Do(x => { throw new NUnitEngineException("Message"); });
110110

111-
var ex = Assert.Throws<NUnitEngineException>(() => _directTestRunner.StopRun(true));
111+
var ex = Assert.Throws<NUnitEngineException>(() => _directTestRunner.ForcedStop());
112112
Assert.That(ex.Message, Is.EqualTo("Message"));
113113
}
114114

@@ -118,7 +118,7 @@ public void StopRun_Throws_NUnitEngineException()
118118
_driver.When(x => x.StopRun(Arg.Any<bool>()))
119119
.Do(x => { throw new ArgumentException("Message"); });
120120

121-
var ex = Assert.Throws<NUnitEngineException>(() => _directTestRunner.StopRun(true));
121+
var ex = Assert.Throws<NUnitEngineException>(() => _directTestRunner.ForcedStop());
122122
Assert.That(ex.InnerException is ArgumentException);
123123
Assert.That(ex.InnerException.Message, Is.EqualTo("Message"));
124124
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
2+
3+
namespace NUnit.Engine.Communication.Messages
4+
{
5+
public class MessageCode
6+
{ // All length 4
7+
public const string StartAgent = "STRT"; // not used
8+
public const string StopAgent = "EXIT";
9+
public const string CreateRunner = "RUNR";
10+
11+
public const string LoadCommand = "LOAD";
12+
public const string ReloadCommand = "RELD";
13+
public const string UnloadCommand = "UNLD";
14+
public const string ExploreCommand = "XPLR";
15+
public const string CountCasesCommand = "CNTC";
16+
public const string RunCommand = "RSYN";
17+
public const string RunAsyncCommand = "RASY";
18+
public const string RequestStopCommand = "STOP";
19+
public const string ForcedStopCommand = "ABRT";
20+
21+
public const string ProgressReport = "PROG";
22+
public const string CommandResult = "RSLT";
23+
}
24+
}

src/NUnitEngine/nunit.engine.core/Communication/Transports/Remoting/TestAgentRemotingTransport.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,16 @@ public AsyncTestEngineResult RunAsync(ITestEventListener listener, TestFilter fi
172172
}
173173

174174
/// <summary>
175-
/// Cancel the ongoing test run. If no test is running, the call is ignored.
175+
/// Request the current test run to stop. If no tests are running,
176+
/// the call is ignored.
176177
/// </summary>
177-
/// <param name="force">If true, cancel any ongoing test threads, otherwise wait for them to complete.</param>
178-
public void StopRun(bool force)
179-
{
180-
if (_runner != null)
181-
_runner.StopRun(force);
182-
}
178+
public void RequestStop() => _runner?.RequestStop();
179+
180+
/// <summary>
181+
/// Force the current test run to stop, killing threads or processes if necessary.
182+
/// If no tests are running, the call is ignored.
183+
/// </summary>
184+
public void ForcedStop() => _runner?.ForcedStop();
183185

184186
#endregion
185187

src/NUnitEngine/nunit.engine.core/ITestEngineRunner.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ public interface ITestEngineRunner : IDisposable
5757
AsyncTestEngineResult RunAsync(ITestEventListener listener, TestFilter filter);
5858

5959
/// <summary>
60-
/// Cancel the current test run. If no test is running,
60+
/// Request the current test run to stop. If no tests are running,
6161
/// the call is ignored.
6262
/// </summary>
63-
/// <param name="force">If true, force a stop by cancelling threads if necessary.</param>
64-
void StopRun(bool force);
63+
void RequestStop();
64+
65+
/// <summary>
66+
/// Force the current test run to stop, killing threads or processes if necessary.
67+
/// If no tests are running, the call is ignored.
68+
/// </summary>
69+
void ForcedStop();
6570

6671
/// <summary>
6772
/// Explore a loaded TestPackage and return information about

src/NUnitEngine/nunit.engine.core/Runners/AbstractTestRunner.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,16 @@ protected virtual AsyncTestEngineResult RunTestsAsync(ITestEventListener listene
104104
}
105105

106106
/// <summary>
107-
/// Cancel the ongoing test run. If no test is running, the call is ignored.
107+
/// Request the current test run to stop. If no tests are running,
108+
/// the call is ignored.
108109
/// </summary>
109-
/// <param name="force">If true, cancel any ongoing test threads, otherwise wait for them to complete.</param>
110-
public abstract void StopRun(bool force);
110+
public abstract void RequestStop();
111+
112+
/// <summary>
113+
/// Force the current test run to stop, killing threads or processes if necessary.
114+
/// If no tests are running, the call is ignored.
115+
/// </summary>
116+
public abstract void ForcedStop();
111117

112118
/// <summary>
113119
/// Explores the TestPackage and returns information about

src/NUnitEngine/nunit.engine.core/Runners/AggregatingTestRunner.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,23 @@ private void RunTestsInParallel(ITestEventListener listener, TestFilter filter,
191191
}
192192

193193
/// <summary>
194-
/// Cancel the ongoing test run. If no test is running, the call is ignored.
194+
/// Request the current test run to stop. If no tests are running,
195+
/// the call is ignored.
195196
/// </summary>
196-
/// <param name="force">If true, cancel any ongoing test threads, otherwise wait for them to complete.</param>
197-
public override void StopRun(bool force)
197+
public override void RequestStop()
198198
{
199199
foreach (var runner in Runners)
200-
runner.StopRun(force);
200+
runner.RequestStop();
201+
}
202+
203+
/// <summary>
204+
/// Force the current test run to stop, killing threads or processes if necessary.
205+
/// If no tests are running, the call is ignored.
206+
/// </summary>
207+
public override void ForcedStop()
208+
{
209+
foreach (var runner in Runners)
210+
runner.ForcedStop();
201211
}
202212

203213
protected override void Dispose(bool disposing)

src/NUnitEngine/nunit.engine.core/Runners/DirectTestRunner.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,18 @@ protected override TestEngineResult RunTests(ITestEventListener listener, TestFi
209209
}
210210

211211
/// <summary>
212-
/// Cancel the ongoing test run. If no test is running, the call is ignored.
212+
/// Request the current test run to stop. If no tests are running,
213+
/// the call is ignored.
213214
/// </summary>
214-
/// <param name="force">If true, cancel any ongoing test threads, otherwise wait for them to complete.</param>
215-
public override void StopRun(bool force)
215+
public override void RequestStop() => StopRun(false);
216+
217+
/// <summary>
218+
/// Force the current test run to stop, killing threads or processes if necessary.
219+
/// If no tests are running, the call is ignored.
220+
/// </summary>
221+
public override void ForcedStop() => StopRun(true);
222+
223+
private void StopRun(bool force)
216224
{
217225
EnsurePackageIsLoaded();
218226

src/NUnitEngine/nunit.engine.core/Runners/NotRunnableTestRunner.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,17 @@ AsyncTestEngineResult ITestEngineRunner.RunAsync(ITestEventListener listener, Te
8080
throw new NotImplementedException();
8181
}
8282

83-
void ITestEngineRunner.StopRun(bool force)
84-
{
85-
}
83+
/// <summary>
84+
/// Request the current test run to stop. If no tests are running,
85+
/// the call is ignored.
86+
/// </summary>
87+
void ITestEngineRunner.RequestStop() { }
88+
89+
/// <summary>
90+
/// Force the current test run to stop, killing threads or processes if necessary.
91+
/// If no tests are running, the call is ignored.
92+
/// </summary>
93+
void ITestEngineRunner.ForcedStop() { }
8694

8795
TestEngineResult ITestEngineRunner.Explore(TestFilter filter)
8896
{

src/NUnitEngine/nunit.engine/Communication/Transports/Tcp/TestAgentTcpProxy.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ public AsyncTestEngineResult RunAsync(ITestEventListener listener, TestFilter fi
8181
//return new AsyncTestEngineResult();
8282
}
8383

84-
public void StopRun(bool force)
85-
{
86-
SendCommandMessage("StopRun", force);
87-
}
84+
public void RequestStop() => SendCommandMessage(MessageCode.RequestStopCommand);
85+
86+
public void ForcedStop() => SendCommandMessage(MessageCode.ForcedStopCommand);
8887

8988
public TestEngineResult Explore(TestFilter filter)
9089
{

src/NUnitEngine/nunit.engine/Runners/MasterTestRunner.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ public ITestRun RunAsync(ITestEventListener listener, TestFilter filter)
169169
/// <param name="force">If true, cancel any ongoing test threads, otherwise wait for them to complete.</param>
170170
public void StopRun(bool force)
171171
{
172-
_engineRunner.StopRun(force);
173-
174-
if (force)
172+
if (!force)
173+
_engineRunner.RequestStop();
174+
else
175175
{
176+
_engineRunner.ForcedStop();
177+
176178
// Frameworks should handle StopRun(true) by cancelling all tests and notifying
177179
// us of the completion of any tests that were running. However, this feature
178180
// may be absent in some frameworks or may be broken and we may not pass on the

0 commit comments

Comments
 (0)