Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch socket network transport to IPV4 #95

Merged
merged 3 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/Akka.HealthCheck.Tests/AkkaHealthCheckIntegrationSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public async Task Should_load_custom_HealthCheck_system_correctly()

// check to see that our probes are up and running using the supplied transports
AwaitCondition(() => File.Exists(filePath));
var tcpClient = new TcpClient(AddressFamily.InterNetworkV6);
await tcpClient.ConnectAsync(IPAddress.IPv6Loopback, tcpPort);
var tcpClient = new TcpClient(AddressFamily.InterNetwork);
await tcpClient.ConnectAsync(IPAddress.Loopback, tcpPort);

// force shutdown of the ActorSystem and verify that probes are stopped
await Sys.Terminate();
Expand All @@ -79,18 +79,12 @@ public async Task Should_load_custom_HealthCheck_system_correctly()
AwaitCondition(() => !File.Exists(filePath));

//Created a new client to see if it would be able to connect.
var tcpClient2 = new TcpClient(AddressFamily.InterNetworkV6);
var tcpClient2 = new TcpClient(AddressFamily.InterNetwork);

// liveness probe should be disconnected
try
{
await tcpClient2.ConnectAsync(IPAddress.IPv6Loopback, tcpPort);
var bytesRead = await tcpClient.GetStream().ReadAsync(new byte[10], 0, 10);
bytesRead.Should().Be(0);
}
catch
{
}
tcpClient2.Awaiting(client => client.ConnectAsync(IPAddress.Loopback, tcpPort))
.Should().Throw<SocketException>();

//Second client should not be able to connect as socket has been closed
AwaitCondition(()=> !tcpClient2.Connected);
}
Expand Down
38 changes: 17 additions & 21 deletions src/Akka.HealthCheck.Tests/Transports/SocketStatusTransportSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Net;
using System.Net.Sockets;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
using Akka.HealthCheck.Transports;
Expand All @@ -32,29 +33,24 @@ public SocketStatusTransportSpecs()
public async Task Should_successfully_open_and_close_signal()
{
var result = await Transport.Go("foo", CancellationToken.None);
if (!result.Success)
ExceptionDispatchInfo.Capture(result.Exception).Throw();

result.Success.Should().BeTrue();

var tcpClient = new TcpClient(AddressFamily.InterNetworkV6);
await tcpClient.ConnectAsync(IPAddress.IPv6Loopback, PortNumber);
var tcpClient = new TcpClient(AddressFamily.InterNetwork);
await tcpClient.ConnectAsync(IPAddress.Loopback, PortNumber);

var deleteResult = await Transport.Stop(null, CancellationToken.None);
deleteResult.Success.Should().BeTrue();

try
{
AwaitAssert(() => tcpClient.GetStream().ReadAsync(new byte[10], 0, 10).Should().Be(8));
}
catch
{
}
await AwaitAssertAsync(async () =>
(await tcpClient.GetStream().ReadAsync(new byte[10], 0, 10)).Should().Be(8));

var tcpClient2 = new TcpClient(AddressFamily.InterNetworkV6);
try
{
await tcpClient2.ConnectAsync(IPAddress.IPv6Loopback, PortNumber);
var tcpClient2 = new TcpClient(AddressFamily.InterNetwork);
//Should throw execption as socket will refuse to establish a connection
}
catch{ }
await tcpClient2.Awaiting(client => client.ConnectAsync(IPAddress.Loopback, PortNumber))
.Should().ThrowAsync<SocketException>();
tcpClient2.Connected.Should().BeFalse();
}

Expand All @@ -74,21 +70,21 @@ public async Task Should_successfully_repeatedly_open_signal()
var result = await Transport.Go("foo", CancellationToken.None);
result.Success.Should().BeTrue();

var tcpClient = new TcpClient(AddressFamily.InterNetworkV6);
await tcpClient.ConnectAsync(IPAddress.IPv6Loopback, PortNumber);
var tcpClient = new TcpClient(AddressFamily.InterNetwork);
await tcpClient.ConnectAsync(IPAddress.Loopback, PortNumber);

var result2 = await Transport.Go("bar", CancellationToken.None);
result.Success.Should().BeTrue();
result2.Success.Should().BeTrue();

AwaitAssert(()=> tcpClient.Available.Should().Be(8));
await AwaitAssertAsync(()=> tcpClient.Available.Should().Be(8));
tcpClient.Connected.Should().BeTrue();

// special case - need to test the NULL pattern
var result3 = await Transport.Go(null, CancellationToken.None);
result.Success.Should().BeTrue();
result3.Success.Should().BeTrue();


AwaitAssert(() => tcpClient.Available.Should().Be(8));
await AwaitAssertAsync(() => tcpClient.Available.Should().Be(8));
tcpClient.Connected.Should().BeTrue();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<TransportWriteStatus> Go(string statusMessage, CancellationTok
{
_abortSocket = new CancellationTokenSource();
_socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
_socket.Bind(new IPEndPoint(IPAddress.IPv6Any, Settings.Port));
_socket.Bind(new IPEndPoint(IPAddress.Any, Settings.Port));
_socket.Listen(10);

// want this to run async, without waiting
Expand Down