Skip to content

Commit 0967647

Browse files
committed
ping probe Timeout implemented
1 parent 3d2b049 commit 0967647

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/QAToolKit.Engine.Probes.Test/Probes/PingProbeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public PingProbeTests(ITestOutputHelper testOutputHelper)
2323
[Fact]
2424
public async Task PingHostNameTest_Success()
2525
{
26-
var pinger = new PingProbe("github.com");
26+
var pinger = new PingProbe("github.com", 500);
2727
var result = await pinger.Execute();
2828

2929
_logger.LogInformation($"Success: {result.Success}");

src/QAToolKit.Engine.Probes/Probes/PingProbe.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class PingProbe : IProbe<PingResult>
1414
{
1515
private readonly string _address;
1616
private readonly string Data = "0000000000000000000000000000000";
17-
private readonly int Timeout = 120;
17+
private readonly int _timeout = 120;
1818

1919
/// <summary>
2020
/// Ping probe constructor
@@ -25,6 +25,17 @@ public PingProbe(string hostName)
2525
_address = hostName;
2626
}
2727

28+
/// <summary>
29+
/// Ping probe constructor
30+
/// </summary>
31+
/// <param name="hostName"></param>
32+
/// <param name="timeout"></param>
33+
public PingProbe(string hostName, int timeout)
34+
{
35+
_address = hostName;
36+
_timeout = timeout;
37+
}
38+
2839
/// <summary>
2940
/// Ping probe constructor
3041
/// </summary>
@@ -34,6 +45,17 @@ public PingProbe(IPAddress ipAddress)
3445
_address = ipAddress.ToString();
3546
}
3647

48+
/// <summary>
49+
/// Ping probe constructor
50+
/// </summary>
51+
/// <param name="ipAddress"></param>
52+
/// <param name="timeout"></param>
53+
public PingProbe(IPAddress ipAddress, int timeout)
54+
{
55+
_address = ipAddress.ToString();
56+
_timeout = timeout;
57+
}
58+
3759
/// <summary>
3860
/// Execute ping probe
3961
/// </summary>
@@ -48,7 +70,7 @@ public async Task<PingResult> Execute()
4870
};
4971

5072
byte[] buffer = Encoding.ASCII.GetBytes(Data);
51-
PingReply reply = await pingSender.SendPingAsync(_address, Timeout, buffer, options);
73+
PingReply reply = await pingSender.SendPingAsync(_address, _timeout, buffer, options);
5274

5375
return new PingResult(reply.Status, reply.Address.ToString(), reply.RoundtripTime, reply.Options?.Ttl, reply.Buffer.Length);
5476
}

0 commit comments

Comments
 (0)