Skip to content

Commit 182716d

Browse files
committed
* Toxiproxy tests fixup.
1 parent 7f4857e commit 182716d

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

projects/Applications/GH-1749/Util.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public class Util : IDisposable
4040
{
4141
private static readonly Random s_random = Random.Shared;
4242
private readonly ManagementClient _managementClient;
43-
private static readonly bool s_isWindows = false;
4443

4544
public Util() : this("localhost", "guest", "guest")
4645
{

projects/Test/Integration/TestToxiproxy.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@
4141
using Xunit;
4242
using Xunit.Abstractions;
4343

44+
#nullable enable
45+
4446
namespace Test.Integration
4547
{
4648
public class TestToxiproxy : IntegrationFixture
4749
{
4850
private readonly TimeSpan _heartbeatTimeout = TimeSpan.FromSeconds(1);
49-
private ToxiproxyManager _toxiproxyManager;
51+
private ToxiproxyManager? _toxiproxyManager;
5052
private int _proxyPort;
5153

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

64-
_toxiproxyManager = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
65-
_proxyPort = ToxiproxyManager.ProxyPort;
66-
return _toxiproxyManager.InitializeAsync();
66+
if (AreToxiproxyTestsEnabled)
67+
{
68+
_toxiproxyManager = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
69+
_proxyPort = ToxiproxyManager.ProxyPort;
70+
return _toxiproxyManager.InitializeAsync();
71+
}
72+
else
73+
{
74+
return Task.CompletedTask;
75+
}
6776
}
6877

6978
public override async Task DisposeAsync()
7079
{
71-
await _toxiproxyManager.DisposeAsync();
80+
if (_toxiproxyManager is not null)
81+
{
82+
await _toxiproxyManager.DisposeAsync();
83+
}
7284
await base.DisposeAsync();
7385
}
7486

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

8194
ConnectionFactory cf = CreateConnectionFactory();
8295
cf.Port = _proxyPort;
@@ -199,6 +212,7 @@ async Task PublishLoop()
199212
public async Task TestThatStoppedSocketResultsInHeartbeatTimeout()
200213
{
201214
Skip.IfNot(AreToxiproxyTestsEnabled, "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test");
215+
Assert.NotNull(_toxiproxyManager);
202216

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

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

302318
const int TotalMessageCount = 64;
303319
const int MaxOutstandingConfirms = 8;
@@ -397,7 +413,7 @@ private bool AreToxiproxyTestsEnabled
397413
{
398414
get
399415
{
400-
string s = Environment.GetEnvironmentVariable("RABBITMQ_TOXIPROXY_TESTS");
416+
string? s = Environment.GetEnvironmentVariable("RABBITMQ_TOXIPROXY_TESTS");
401417

402418
if (string.IsNullOrEmpty(s))
403419
{

0 commit comments

Comments
 (0)