Skip to content

Commit

Permalink
* Toxiproxy tests fixup.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebakken committed Dec 20, 2024
1 parent 7f4857e commit 182716d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
1 change: 0 additions & 1 deletion projects/Applications/GH-1749/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class Util : IDisposable
{
private static readonly Random s_random = Random.Shared;
private readonly ManagementClient _managementClient;
private static readonly bool s_isWindows = false;

public Util() : this("localhost", "guest", "guest")
{
Expand Down
28 changes: 22 additions & 6 deletions projects/Test/Integration/TestToxiproxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@
using Xunit;
using Xunit.Abstractions;

#nullable enable

namespace Test.Integration
{
public class TestToxiproxy : IntegrationFixture
{
private readonly TimeSpan _heartbeatTimeout = TimeSpan.FromSeconds(1);
private ToxiproxyManager _toxiproxyManager;
private ToxiproxyManager? _toxiproxyManager;
private int _proxyPort;

public TestToxiproxy(ITestOutputHelper output) : base(output)
Expand All @@ -61,14 +63,24 @@ public override Task InitializeAsync()
Assert.Null(_conn);
Assert.Null(_channel);

_toxiproxyManager = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
_proxyPort = ToxiproxyManager.ProxyPort;
return _toxiproxyManager.InitializeAsync();
if (AreToxiproxyTestsEnabled)
{
_toxiproxyManager = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
_proxyPort = ToxiproxyManager.ProxyPort;
return _toxiproxyManager.InitializeAsync();
}
else
{
return Task.CompletedTask;
}
}

public override async Task DisposeAsync()
{
await _toxiproxyManager.DisposeAsync();
if (_toxiproxyManager is not null)
{
await _toxiproxyManager.DisposeAsync();
}
await base.DisposeAsync();
}

Expand All @@ -77,6 +89,7 @@ public override async Task DisposeAsync()
public async Task TestCloseConnection()
{
Skip.IfNot(AreToxiproxyTestsEnabled, "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test");
Assert.NotNull(_toxiproxyManager);

ConnectionFactory cf = CreateConnectionFactory();
cf.Port = _proxyPort;
Expand Down Expand Up @@ -199,6 +212,7 @@ async Task PublishLoop()
public async Task TestThatStoppedSocketResultsInHeartbeatTimeout()
{
Skip.IfNot(AreToxiproxyTestsEnabled, "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test");
Assert.NotNull(_toxiproxyManager);

ConnectionFactory cf = CreateConnectionFactory();
cf.Port = _proxyPort;
Expand Down Expand Up @@ -246,6 +260,7 @@ await Assert.ThrowsAsync<AlreadyClosedException>(() =>
public async Task TestTcpReset_GH1464()
{
Skip.IfNot(AreToxiproxyTestsEnabled, "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test");
Assert.NotNull(_toxiproxyManager);

ConnectionFactory cf = CreateConnectionFactory();
cf.Endpoint = new AmqpTcpEndpoint(IPAddress.Loopback.ToString(), _proxyPort);
Expand Down Expand Up @@ -298,6 +313,7 @@ public async Task TestTcpReset_GH1464()
public async Task TestPublisherConfirmationThrottling()
{
Skip.IfNot(AreToxiproxyTestsEnabled, "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test");
Assert.NotNull(_toxiproxyManager);

const int TotalMessageCount = 64;
const int MaxOutstandingConfirms = 8;
Expand Down Expand Up @@ -397,7 +413,7 @@ private bool AreToxiproxyTestsEnabled
{
get
{
string s = Environment.GetEnvironmentVariable("RABBITMQ_TOXIPROXY_TESTS");
string? s = Environment.GetEnvironmentVariable("RABBITMQ_TOXIPROXY_TESTS");

if (string.IsNullOrEmpty(s))
{
Expand Down

0 comments on commit 182716d

Please sign in to comment.