Skip to content

Commit

Permalink
fixed RandomUdpPortBinding test
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfman42 committed Jul 23, 2024
1 parent a94bca2 commit 1771e16
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 61 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ jobs:
run: dotnet cake --target=Build

- name: Run Tests
# run: dotnet cake --target=Tests --test-filter=${{ startsWith(matrix.os, 'ubuntu') && 'FullyQualifiedName~Testcontainers' || 'DockerPlatform=Windows' }}
run: dotnet cake --target=Tests --test-filter='FullyQualifiedName~RandomUdpPortBinding'
run: dotnet cake --target=Tests --test-filter=${{ startsWith(matrix.os, 'ubuntu') && 'FullyQualifiedName~Testcontainers' || 'DockerPlatform=Windows' }}

# The Test Reporter GH Action is not compatible with the recent
# actions/upload-artifact@v4 updates: https://github.com/dorny/test-reporter/issues/363.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,65 +229,6 @@ await container.StartAsync()
Assert.NotEqual(containerPort, container.GetMappedPublicPort("161/udp"));
}

[Fact(Skip = "UDP server doesn't work")]
public async Task RandomUdpPortBindingUdpServer()
{
// Given
const string containerUdpQualifiedPort = "4001/udp";
const ushort containerUdpPort = 4001;

// Simple Python-based echo server with UDP
// https://github.com/vhiribarren/docker-echo-server
await using var container = new ContainerBuilder()
// .WithImage("docker-hub.artifactory.mocca.yunextraffic.cloud/vhiribarren/echo-server")
.WithImage("vhiribarren/echo-server")
.WithPortBinding(containerUdpQualifiedPort, true)
.Build();

// When
await container.StartAsync()
.ConfigureAwait(true);

// Then
var localMappedPort = container.GetMappedPublicPort(containerUdpQualifiedPort);
Assert.NotEqual(containerUdpPort, localMappedPort);

var message = Guid.NewGuid().ToString("D");
var response = CallUdpEchoServer("127.0.0.1", localMappedPort, message);
// var response = CallUdpEchoServer("172.19.212.239", localMappedPort, message);
// response will look like this: "UDP: fb15aa0b4d19 received: <message> from ('<IP>', <Port>)
Assert.Contains(message, response);
}

private string CallUdpEchoServer(string serverIP, int serverPort, string message)
{
// Create a UDP client
// UdpClient client = new UdpClient(0, AddressFamily.InterNetwork);
UdpClient client = new UdpClient();

try
{
// Connect to the server
client.Connect(serverIP, serverPort);

// Send data to the server
byte[] sendData = Encoding.ASCII.GetBytes(message);
client.Send(sendData, sendData.Length);

// Receive the response from the server
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
byte[] receiveData = client.Receive(ref remoteEndPoint);
string receivedMessage = Encoding.ASCII.GetString(receiveData);

return receivedMessage;
}
finally
{
// Close the client
client.Close();
}
}

[Fact]
public async Task BindMountAndCommand()
{
Expand Down

0 comments on commit 1771e16

Please sign in to comment.