41
41
using Xunit ;
42
42
using Xunit . Abstractions ;
43
43
44
+ #nullable enable
45
+
44
46
namespace Test . Integration
45
47
{
46
48
public class TestToxiproxy : IntegrationFixture
47
49
{
48
50
private readonly TimeSpan _heartbeatTimeout = TimeSpan . FromSeconds ( 1 ) ;
49
- private ToxiproxyManager _toxiproxyManager ;
51
+ private ToxiproxyManager ? _toxiproxyManager ;
50
52
private int _proxyPort ;
51
53
52
54
public TestToxiproxy ( ITestOutputHelper output ) : base ( output )
@@ -61,14 +63,24 @@ public override Task InitializeAsync()
61
63
Assert . Null ( _conn ) ;
62
64
Assert . Null ( _channel ) ;
63
65
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
+ }
67
76
}
68
77
69
78
public override async Task DisposeAsync ( )
70
79
{
71
- await _toxiproxyManager . DisposeAsync ( ) ;
80
+ if ( _toxiproxyManager is not null )
81
+ {
82
+ await _toxiproxyManager . DisposeAsync ( ) ;
83
+ }
72
84
await base . DisposeAsync ( ) ;
73
85
}
74
86
@@ -77,6 +89,7 @@ public override async Task DisposeAsync()
77
89
public async Task TestCloseConnection ( )
78
90
{
79
91
Skip . IfNot ( AreToxiproxyTestsEnabled , "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test" ) ;
92
+ Assert . NotNull ( _toxiproxyManager ) ;
80
93
81
94
ConnectionFactory cf = CreateConnectionFactory ( ) ;
82
95
cf . Port = _proxyPort ;
@@ -199,6 +212,7 @@ async Task PublishLoop()
199
212
public async Task TestThatStoppedSocketResultsInHeartbeatTimeout ( )
200
213
{
201
214
Skip . IfNot ( AreToxiproxyTestsEnabled , "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test" ) ;
215
+ Assert . NotNull ( _toxiproxyManager ) ;
202
216
203
217
ConnectionFactory cf = CreateConnectionFactory ( ) ;
204
218
cf . Port = _proxyPort ;
@@ -246,6 +260,7 @@ await Assert.ThrowsAsync<AlreadyClosedException>(() =>
246
260
public async Task TestTcpReset_GH1464 ( )
247
261
{
248
262
Skip . IfNot ( AreToxiproxyTestsEnabled , "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test" ) ;
263
+ Assert . NotNull ( _toxiproxyManager ) ;
249
264
250
265
ConnectionFactory cf = CreateConnectionFactory ( ) ;
251
266
cf . Endpoint = new AmqpTcpEndpoint ( IPAddress . Loopback . ToString ( ) , _proxyPort ) ;
@@ -298,6 +313,7 @@ public async Task TestTcpReset_GH1464()
298
313
public async Task TestPublisherConfirmationThrottling ( )
299
314
{
300
315
Skip . IfNot ( AreToxiproxyTestsEnabled , "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test" ) ;
316
+ Assert . NotNull ( _toxiproxyManager ) ;
301
317
302
318
const int TotalMessageCount = 64 ;
303
319
const int MaxOutstandingConfirms = 8 ;
@@ -397,7 +413,7 @@ private bool AreToxiproxyTestsEnabled
397
413
{
398
414
get
399
415
{
400
- string s = Environment . GetEnvironmentVariable ( "RABBITMQ_TOXIPROXY_TESTS" ) ;
416
+ string ? s = Environment . GetEnvironmentVariable ( "RABBITMQ_TOXIPROXY_TESTS" ) ;
401
417
402
418
if ( string . IsNullOrEmpty ( s ) )
403
419
{
0 commit comments