Skip to content

Commit

Permalink
stopping infinite ping
Browse files Browse the repository at this point in the history
  • Loading branch information
tienv9 committed Dec 10, 2024
1 parent 1fa909d commit 48adfe4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Assignment.Tests/PingProcessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void TestInitialize()
[TestMethod]
public void Start_PingProcess_Success()
{
Process process = Process.Start("ping", "localhost");
Process process = Process.Start("ping", "-n 4 localhost");
process.WaitForExit();
Assert.AreEqual<int>(0, process.ExitCode);
}
Expand Down Expand Up @@ -51,16 +51,16 @@ public void Run_InvalidAddressOutput_Success()
[TestMethod]
public void Run_CaptureStdOutput_Success()
{
PingResult result = Sut.Run("localhost");
PingResult result = Sut.Run("-n 4 localhost");
AssertValidPingOutput(result);
}

[TestMethod]
public void RunTaskAsync_Success()
{
// Do NOT use async/await in this test.
// Test Sut.RunTaskAsync("localhost");
Task<PingResult> result = Sut.RunTaskAsync("localhost");
// Test Sut.RunTaskAsync("-n 4 localhost");
Task<PingResult> result = Sut.RunTaskAsync("-n 4 localhost");
//result.Wait();

AssertValidPingOutput(result.Result);
Expand All @@ -70,18 +70,18 @@ public void RunTaskAsync_Success()
public void RunAsync_UsingTaskReturn_Success()
{
// Do NOT use async/await in this test.
PingResult result = Sut.RunAsync("localhost").Result;
// Test Sut.RunAsync("localhost");
PingResult result = Sut.RunAsync("-n 4 localhost").Result;
// Test Sut.RunAsync("-n 4 localhost");
AssertValidPingOutput(result);
}

[TestMethod]
async public Task RunAsync_UsingTpl_Success()
{
// DO use async/await in this test.
PingResult result = await Sut.RunAsync("localhost");
PingResult result = await Sut.RunAsync("-n 4 localhost");

// Test Sut.RunAsync("localhost");
// Test Sut.RunAsync("-n 4 localhost");
AssertValidPingOutput(result);
}

Expand All @@ -93,7 +93,7 @@ public void RunAsync_UsingTplWithCancellation_CatchAggregateExceptionWrapping()

CancellationTokenSource cts = new();
var token = cts.Token;
Task<PingResult> pr = Sut.RunAsync("localhost", token);
Task<PingResult> pr = Sut.RunAsync("-n 4 localhost", token);
cts.Cancel();
PingResult temp = pr.Result;

Expand All @@ -108,7 +108,7 @@ public void RunAsync_UsingTplWithCancellation_CatchAggregateExceptionWrappingTas
{

CancellationTokenSource cts = new();
Task<PingResult> pr = Sut.RunAsync("localhost", cts.Token);
Task<PingResult> pr = Sut.RunAsync("-n 4 localhost", cts.Token);
cts.Cancel();
PingResult asdf = pr.Result;
}
Expand All @@ -126,7 +126,7 @@ public void RunAsync_UsingTplWithCancellation_CatchAggregateExceptionWrappingTas
[TestMethod]
async public Task RunAsync_MultipleHostAddresses_True()
{
string[] hostNames = new string[] { "localhost", "localhost", "localhost", "localhost" };
string[] hostNames = new string[] { "-n 4 localhost", "-n 4 localhost", "-n 4 localhost", "-n 4 localhost" };
int expectedLineCount = PingOutputLikeExpression.Split(Environment.NewLine).Length*hostNames.Length;
PingResult result = await Sut.RunAsync(hostNames);
int? lineCount = result.StdOutput?.TrimEnd().Split(Environment.NewLine).Length;
Expand All @@ -136,7 +136,7 @@ async public Task RunAsync_MultipleHostAddresses_True()
[TestMethod]
async public Task RunLongRunningAsync_UsingTpl_Success()
{
var startInfo = new ProcessStartInfo("ping", "localhost");
var startInfo = new ProcessStartInfo("ping", "-n 4 localhost");
int exitCode = await Sut.RunLongRunningAsync(startInfo, null, null, default);
Assert.AreEqual(0, exitCode);
}
Expand Down

0 comments on commit 48adfe4

Please sign in to comment.