consolidate the tests locations
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Channels;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using StellaOps.Router.Common.Enums;
|
||||
using StellaOps.Router.Common.Frames;
|
||||
using StellaOps.Router.Common.Models;
|
||||
using StellaOps.Router.Transport.InMemory;
|
||||
using StellaOps.Router.Transport.Tls;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Router.Transport.Tcp.Tests;
|
||||
|
||||
@@ -122,13 +128,21 @@ public sealed class ConnectionFailureTests : IDisposable
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
Port = _port,
|
||||
ConnectionTimeout = TimeSpan.FromSeconds(1)
|
||||
ConnectTimeout = TimeSpan.FromSeconds(1)
|
||||
};
|
||||
|
||||
var client = new TcpTransportClient(options, _clientLogger);
|
||||
var client = new TcpTransportClient(Options.Create(options), _clientLogger);
|
||||
var instance = new InstanceDescriptor
|
||||
{
|
||||
InstanceId = Guid.NewGuid().ToString("N"),
|
||||
ServiceName = "test-service",
|
||||
Version = "1.0.0",
|
||||
Region = "local"
|
||||
};
|
||||
var endpoints = Array.Empty<EndpointDescriptor>();
|
||||
|
||||
// Act & Assert
|
||||
var action = async () => await client.ConnectAsync(default);
|
||||
var action = async () => await client.ConnectAsync(instance, endpoints, default);
|
||||
await action.Should().ThrowAsync<Exception>();
|
||||
|
||||
await client.DisposeAsync();
|
||||
@@ -141,13 +155,21 @@ public sealed class ConnectionFailureTests : IDisposable
|
||||
{
|
||||
Host = "invalid.hostname.that.does.not.exist.local",
|
||||
Port = 12345,
|
||||
ConnectionTimeout = TimeSpan.FromSeconds(2)
|
||||
ConnectTimeout = TimeSpan.FromSeconds(2)
|
||||
};
|
||||
|
||||
var client = new TcpTransportClient(options, _clientLogger);
|
||||
var client = new TcpTransportClient(Options.Create(options), _clientLogger);
|
||||
var instance = new InstanceDescriptor
|
||||
{
|
||||
InstanceId = Guid.NewGuid().ToString("N"),
|
||||
ServiceName = "test-service",
|
||||
Version = "1.0.0",
|
||||
Region = "local"
|
||||
};
|
||||
var endpoints = Array.Empty<EndpointDescriptor>();
|
||||
|
||||
// Act & Assert
|
||||
var action = async () => await client.ConnectAsync(default);
|
||||
var action = async () => await client.ConnectAsync(instance, endpoints, default);
|
||||
await action.Should().ThrowAsync<Exception>();
|
||||
|
||||
await client.DisposeAsync();
|
||||
@@ -261,17 +283,25 @@ public sealed class ConnectionFailureTests : IDisposable
|
||||
{
|
||||
Host = "10.255.255.1", // Non-routable address to force timeout
|
||||
Port = 12345,
|
||||
ConnectionTimeout = TimeSpan.FromMilliseconds(500)
|
||||
ConnectTimeout = TimeSpan.FromMilliseconds(500)
|
||||
};
|
||||
|
||||
var client = new TcpTransportClient(options, _clientLogger);
|
||||
var client = new TcpTransportClient(Options.Create(options), _clientLogger);
|
||||
var instance = new InstanceDescriptor
|
||||
{
|
||||
InstanceId = Guid.NewGuid().ToString("N"),
|
||||
ServiceName = "test-service",
|
||||
Version = "1.0.0",
|
||||
Region = "local"
|
||||
};
|
||||
var endpoints = Array.Empty<EndpointDescriptor>();
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
|
||||
|
||||
// Act
|
||||
var sw = System.Diagnostics.Stopwatch.StartNew();
|
||||
try
|
||||
{
|
||||
await client.ConnectAsync(cts.Token);
|
||||
await client.ConnectAsync(instance, endpoints, cts.Token);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -296,13 +326,21 @@ public sealed class ConnectionFailureTests : IDisposable
|
||||
{
|
||||
Host = "10.255.255.1", // Non-routable to force long connection attempt
|
||||
Port = 12345,
|
||||
ConnectionTimeout = TimeSpan.FromSeconds(30)
|
||||
ConnectTimeout = TimeSpan.FromSeconds(30)
|
||||
};
|
||||
|
||||
var client = new TcpTransportClient(options, _clientLogger);
|
||||
|
||||
var client = new TcpTransportClient(Options.Create(options), _clientLogger);
|
||||
var instance = new InstanceDescriptor
|
||||
{
|
||||
InstanceId = Guid.NewGuid().ToString("N"),
|
||||
ServiceName = "test-service",
|
||||
Version = "1.0.0",
|
||||
Region = "local"
|
||||
};
|
||||
var endpoints = Array.Empty<EndpointDescriptor>();
|
||||
|
||||
// Start connection in background
|
||||
var connectTask = client.ConnectAsync(default);
|
||||
var connectTask = client.ConnectAsync(instance, endpoints, default);
|
||||
|
||||
// Give it a moment to start
|
||||
await Task.Delay(100);
|
||||
@@ -400,7 +438,7 @@ public sealed class ConnectionFailureTests : IDisposable
|
||||
Port = _port
|
||||
};
|
||||
|
||||
var client = new TcpTransportClient(options, _clientLogger);
|
||||
var client = new TcpTransportClient(Options.Create(options), _clientLogger);
|
||||
|
||||
// Before ConnectAsync, client should not be connected
|
||||
// The internal state should be "not connected"
|
||||
@@ -442,12 +480,12 @@ public sealed class TlsConnectionFailureTests
|
||||
Port = 443,
|
||||
MaxReconnectAttempts = 3,
|
||||
MaxReconnectBackoff = TimeSpan.FromSeconds(15),
|
||||
SslProtocols = System.Security.Authentication.SslProtocols.Tls13
|
||||
EnabledProtocols = System.Security.Authentication.SslProtocols.Tls13
|
||||
};
|
||||
|
||||
options.MaxReconnectAttempts.Should().Be(3);
|
||||
options.MaxReconnectBackoff.Should().Be(TimeSpan.FromSeconds(15));
|
||||
options.SslProtocols.Should().Be(System.Security.Authentication.SslProtocols.Tls13);
|
||||
options.EnabledProtocols.Should().Be(System.Security.Authentication.SslProtocols.Tls13);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -464,8 +502,8 @@ public sealed class TlsConnectionFailureTests
|
||||
{
|
||||
Host = "self-signed.badssl.com",
|
||||
Port = 443,
|
||||
TargetHost = "self-signed.badssl.com",
|
||||
ConnectionTimeout = TimeSpan.FromSeconds(5)
|
||||
ExpectedServerHostname = "self-signed.badssl.com",
|
||||
ConnectTimeout = TimeSpan.FromSeconds(5)
|
||||
};
|
||||
|
||||
// The connection should fail due to certificate validation
|
||||
@@ -530,13 +568,14 @@ public sealed class InMemoryConnectionFailureTests
|
||||
await channel.ToMicroservice.Reader.ReadAsync();
|
||||
Assert.Fail("Should have thrown");
|
||||
}
|
||||
catch (ChannelClosedException)
|
||||
{
|
||||
// ChannelClosedException inherits from InvalidOperationException, so catch it first
|
||||
// When channel is completed with an error, ReadAsync throws ChannelClosedException
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
ex.Message.Should().Be("Simulated failure");
|
||||
}
|
||||
catch (ChannelClosedException)
|
||||
{
|
||||
// Also acceptable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,12 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\StellaOps.Router.Transport.Tcp\StellaOps.Router.Transport.Tcp.csproj" />
|
||||
<ProjectReference Include="..\..\StellaOps.Router.Transport.Tls\StellaOps.Router.Transport.Tls.csproj" />
|
||||
<ProjectReference Include="..\..\StellaOps.Router.Transport.InMemory\StellaOps.Router.Transport.InMemory.csproj" />
|
||||
<ProjectReference Include="..\..\StellaOps.Router.Common\StellaOps.Router.Common.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
<Using Include="FluentAssertions" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -52,7 +52,7 @@ public sealed class TcpTransportComplianceTests
|
||||
restored.Method.Should().Be(request.Method);
|
||||
restored.Path.Should().Be(request.Path);
|
||||
restored.Headers.Should().BeEquivalentTo(request.Headers);
|
||||
restored.Payload.ToArray().Should().BeEquivalentTo(request.Payload);
|
||||
restored.Payload.ToArray().Should().Equal(request.Payload.ToArray());
|
||||
restored.TimeoutSeconds.Should().Be(request.TimeoutSeconds);
|
||||
restored.SupportsStreaming.Should().Be(request.SupportsStreaming);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public sealed class TcpTransportComplianceTests
|
||||
restored!.RequestId.Should().Be(response.RequestId);
|
||||
restored.StatusCode.Should().Be(response.StatusCode);
|
||||
restored.Headers.Should().BeEquivalentTo(response.Headers);
|
||||
restored.Payload.ToArray().Should().BeEquivalentTo(response.Payload);
|
||||
restored.Payload.ToArray().Should().Equal(response.Payload.ToArray());
|
||||
restored.HasMoreChunks.Should().Be(response.HasMoreChunks);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,4 +23,8 @@
|
||||
<ProjectReference Include="..\..\StellaOps.Router.Transport.Tls\StellaOps.Router.Transport.Tls.csproj" />
|
||||
<ProjectReference Include="..\..\StellaOps.Router.Common\StellaOps.Router.Common.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
<Using Include="FluentAssertions" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -4,9 +4,11 @@ using System.Security.Authentication;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using StellaOps.Router.Common.Enums;
|
||||
using StellaOps.Router.Common.Frames;
|
||||
using StellaOps.Router.Common.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Router.Transport.Tls.Tests;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user