Skip to content

Commit a06b3f5

Browse files
committed
Using constants constants
1 parent 0848691 commit a06b3f5

File tree

5 files changed

+48
-31
lines changed

5 files changed

+48
-31
lines changed

libs/little-forker/src/LittleForker/ProcessSupervisor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
namespace Logicality.LittleForker;
88

9+
public class ProcessSupervisorSettings
10+
{
11+
public ProcessSupervisorSettings()
12+
{
13+
14+
}
15+
}
16+
917
/// <summary>
1018
/// Launches an process and tracks it's lifecycle .
1119
/// </summary>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
namespace Logicality.LittleForker;
3+
4+
internal static class Constants
5+
{
6+
internal const string DotNet = "dotnet";
7+
internal const string NonTerminatingProcessPath = "./NonTerminatingProcess/Logicality.NonTerminatingProcess.dll";
8+
internal const string SelfTerminatingProcessPath = "./SelfTerminatingProcess/Logicality.SelfTerminatingProcess.dll";
9+
}

libs/little-forker/tests/LittleForker.Tests/CooperativeShutdownTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public async Task When_server_signals_exit_then_should_notify_client_to_exit()
2323
() => exitCalled.SetResult(true),
2424
_loggerFactory);
2525

26-
await CooperativeShutdown.SignalExit(Process.GetCurrentProcess().Id, _loggerFactory);
26+
await CooperativeShutdown.SignalExit(Environment.ProcessId, _loggerFactory);
2727

2828
(await exitCalled.Task).ShouldBeTrue();
2929

libs/little-forker/tests/LittleForker.Tests/ProcessExitedHelperTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ public async Task When_parent_process_exits_than_should_call_parent_exited_callb
3535
_loggerFactory,
3636
ProcessRunType.NonTerminating,
3737
Environment.CurrentDirectory,
38-
"dotnet",
39-
"./NonTerminatingProcess/NonTerminatingProcess.dll");
38+
Constants.DotNet,
39+
Constants.NonTerminatingProcessPath);
4040
var parentIsRunning = supervisor.WhenStateIs(ProcessSupervisor.State.Running);
4141
supervisor.OutputDataReceived += data => _outputHelper.WriteLine($"Parent Process: {data}");
4242
await supervisor.Start();
4343
await parentIsRunning;
4444

4545
// Monitor parent
4646
var parentExited = new TaskCompletionSource<int?>();
47-
using (new ProcessExitedHelper(supervisor.ProcessInfo.Id, watcher => parentExited.SetResult(watcher.ProcessId), _loggerFactory))
47+
using (new ProcessExitedHelper(supervisor.ProcessInfo!.Id, watcher => parentExited.SetResult(watcher.ProcessId), _loggerFactory))
4848
{
4949
// Stop parent
5050
await supervisor.Stop(TimeSpan.FromSeconds(2));
5151
var processId = await parentExited.Task.TimeoutAfter(TimeSpan.FromSeconds(2));
52-
processId.Value.ShouldBeGreaterThan(0);
52+
processId!.Value.ShouldBeGreaterThan(0);
5353
}
5454
}
5555

@@ -61,8 +61,8 @@ public async Task When_parent_process_exits_then_child_process_should_also_do_so
6161
_loggerFactory,
6262
ProcessRunType.NonTerminating,
6363
Environment.CurrentDirectory,
64-
"dotnet",
65-
"./NonTerminatingProcess/NonTerminatingProcess.dll");
64+
Constants.DotNet,
65+
Constants.NonTerminatingProcessPath);
6666
parentSupervisor.OutputDataReceived += data => _outputHelper.WriteLine($"Parent: {data}");
6767
var parentIsRunning = parentSupervisor.WhenStateIs(ProcessSupervisor.State.Running);
6868
await parentSupervisor.Start();
@@ -73,8 +73,8 @@ public async Task When_parent_process_exits_then_child_process_should_also_do_so
7373
_loggerFactory,
7474
ProcessRunType.SelfTerminating,
7575
Environment.CurrentDirectory,
76-
"dotnet",
77-
$"./NonTerminatingProcess/NonTerminatingProcess.dll --ParentProcessId={parentSupervisor.ProcessInfo.Id}");
76+
Constants.DotNet,
77+
$"{Constants.NonTerminatingProcessPath} --ParentProcessId={parentSupervisor.ProcessInfo!.Id}");
7878
childSupervisor.OutputDataReceived += data => _outputHelper.WriteLine($"Child: {data}");
7979
var childIsRunning = childSupervisor.WhenStateIs(ProcessSupervisor.State.Running);
8080
var childHasStopped = childSupervisor.WhenStateIs(ProcessSupervisor.State.ExitedSuccessfully);

libs/little-forker/tests/LittleForker.Tests/ProcessSupervisorTests.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public async Task Given_short_running_exe_then_should_run_to_exit()
5252
_loggerFactory,
5353
ProcessRunType.SelfTerminating,
5454
Environment.CurrentDirectory,
55-
"dotnet",
56-
"./SelfTerminatingProcess/Logicality.SelfTerminatingProcess.dll",
55+
Constants.DotNet,
56+
Constants.SelfTerminatingProcessPath,
5757
envVars);
5858
supervisor.OutputDataReceived += data => _outputHelper.WriteLine2(data);
5959
var whenStateIsExited = supervisor.WhenStateIs(ProcessSupervisor.State.ExitedSuccessfully);
@@ -66,7 +66,7 @@ public async Task Given_short_running_exe_then_should_run_to_exit()
6666
task.ShouldBe(whenStateIsExited);
6767
supervisor.CurrentState.ShouldBe(ProcessSupervisor.State.ExitedSuccessfully);
6868
supervisor.OnStartException.ShouldBeNull();
69-
supervisor.ProcessInfo.ExitCode.ShouldBe(0);
69+
supervisor.ProcessInfo!.ExitCode.ShouldBe(0);
7070
}
7171

7272
[Fact]
@@ -76,8 +76,8 @@ public async Task Given_non_terminating_process_then_should_exit_when_stopped()
7676
_loggerFactory,
7777
ProcessRunType.NonTerminating,
7878
Environment.CurrentDirectory,
79-
"dotnet",
80-
"./NonTerminatingProcess/Logicality.NonTerminatingProcess.dll");
79+
Constants.DotNet,
80+
Constants.NonTerminatingProcessPath);
8181
supervisor.OutputDataReceived += data => _outputHelper.WriteLine2($"Process: {data}");
8282
var running = supervisor.WhenStateIs(ProcessSupervisor.State.Running);
8383
await supervisor.Start();
@@ -99,9 +99,9 @@ public async Task Can_restart_a_stopped_short_running_process()
9999
_loggerFactory,
100100
ProcessRunType.SelfTerminating,
101101
Environment.CurrentDirectory,
102-
"dotnet",
103-
"./SelfTerminatingProcess/Logicality.SelfTerminatingProcess.dll");
104-
supervisor.OutputDataReceived += data => _outputHelper.WriteLine2(data);
102+
Constants.DotNet,
103+
Constants.SelfTerminatingProcessPath);
104+
supervisor.OutputDataReceived += _outputHelper.WriteLine2;
105105
var stateIsStopped = supervisor.WhenStateIs(ProcessSupervisor.State.ExitedSuccessfully);
106106
await supervisor.Start();
107107
await stateIsStopped;
@@ -117,9 +117,9 @@ public async Task Can_restart_a_stopped_long_running_process()
117117
_loggerFactory,
118118
ProcessRunType.NonTerminating,
119119
Environment.CurrentDirectory,
120-
"dotnet",
121-
"./NonTerminatingProcess/Logicality.NonTerminatingProcess.dll");
122-
supervisor.OutputDataReceived += data => _outputHelper.WriteLine2(data);
120+
Constants.DotNet,
121+
Constants.NonTerminatingProcessPath);
122+
supervisor.OutputDataReceived += _outputHelper.WriteLine2;
123123
var exitedKilled = supervisor.WhenStateIs(ProcessSupervisor.State.ExitedKilled);
124124
await supervisor.Start();
125125
await supervisor.Stop();
@@ -139,9 +139,9 @@ public async Task When_stop_a_non_terminating_process_without_a_timeout_then_sho
139139
_loggerFactory,
140140
ProcessRunType.NonTerminating,
141141
Environment.CurrentDirectory,
142-
"dotnet",
143-
"./NonTerminatingProcess/Logicality.NonTerminatingProcess.dll");
144-
supervisor.OutputDataReceived += data => _outputHelper.WriteLine2(data);
142+
Constants.DotNet,
143+
Constants.NonTerminatingProcessPath);
144+
supervisor.OutputDataReceived += _outputHelper.WriteLine2;
145145
var stateIsStopped = supervisor.WhenStateIs(ProcessSupervisor.State.ExitedKilled);
146146
await supervisor.Start();
147147
await supervisor.Stop(); // No timeout so will just kill the process
@@ -157,15 +157,15 @@ public async Task When_stop_a_non_terminating_process_that_does_not_shutdown_wit
157157
_loggerFactory,
158158
ProcessRunType.NonTerminating,
159159
Environment.CurrentDirectory,
160-
"dotnet",
161-
"./NonTerminatingProcess/Logicality.NonTerminatingProcess.dll --ignore-shutdown-signal=true");
162-
supervisor.OutputDataReceived += data => _outputHelper.WriteLine2(data);
160+
Constants.DotNet,
161+
$"{Constants.NonTerminatingProcessPath} --ignore-shutdown-signal=true");
162+
supervisor.OutputDataReceived += _outputHelper.WriteLine2;
163163
var stateIsKilled = supervisor.WhenStateIs(ProcessSupervisor.State.ExitedKilled);
164164
await supervisor.Start();
165165
await supervisor.Stop(TimeSpan.FromSeconds(2));
166166
await stateIsKilled.TimeoutAfter(TimeSpan.FromSeconds(5));
167167

168-
_outputHelper.WriteLine($"Exit code {supervisor.ProcessInfo.ExitCode}");
168+
_outputHelper.WriteLine($"Exit code {supervisor.ProcessInfo!.ExitCode}");
169169
}
170170

171171
[Fact]
@@ -175,14 +175,14 @@ public async Task When_stop_a_non_terminating_process_with_non_zero_then_should_
175175
_loggerFactory,
176176
ProcessRunType.NonTerminating,
177177
Environment.CurrentDirectory,
178-
"dotnet",
179-
"./NonTerminatingProcess/Logicality.NonTerminatingProcess.dll --exit-with-non-zero=true");
180-
supervisor.OutputDataReceived += data => _outputHelper.WriteLine2(data);
178+
Constants.DotNet,
179+
$"{Constants.NonTerminatingProcessPath} --exit-with-non-zero=true");
180+
supervisor.OutputDataReceived += _outputHelper.WriteLine2;
181181
var stateExitWithError = supervisor.WhenStateIs(ProcessSupervisor.State.ExitedWithError);
182182
await supervisor.Start();
183183
await supervisor.Stop(TimeSpan.FromSeconds(5));
184184
await stateExitWithError.TimeoutAfter(TimeSpan.FromSeconds(5));
185-
supervisor.ProcessInfo.ExitCode.ShouldNotBe(0);
185+
supervisor.ProcessInfo!.ExitCode.ShouldNotBe(0);
186186

187187
_outputHelper.WriteLine($"Exit code {supervisor.ProcessInfo.ExitCode}");
188188
}

0 commit comments

Comments
 (0)