Skip to content

Commit e6f65e1

Browse files
committed
Port more of #1164 to this PR
1 parent 0003602 commit e6f65e1

28 files changed

+147
-34
lines changed

projects/Unit/Fixtures.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@
4242

4343
using NUnit.Framework;
4444

45-
using RabbitMQ.Client.Framing;
4645
using RabbitMQ.Client.Framing.Impl;
4746

4847
namespace RabbitMQ.Client.Unit
4948
{
50-
5149
public class IntegrationFixture
5250
{
5351
internal IConnectionFactory ConnFactory;
@@ -56,6 +54,12 @@ public class IntegrationFixture
5654

5755
internal Encoding encoding = new UTF8Encoding();
5856
public static TimeSpan RECOVERY_INTERVAL = TimeSpan.FromSeconds(2);
57+
protected readonly string _testDisplayName;
58+
59+
public IntegrationFixture()
60+
{
61+
_testDisplayName = TestContext.CurrentContext.Test.FullName;
62+
}
5963

6064
[SetUp]
6165
public virtual void Init()
@@ -72,6 +76,7 @@ public void Dispose()
7276
{
7377
Model.Close();
7478
}
79+
7580
if(Conn.IsOpen)
7681
{
7782
Conn.Close();
@@ -106,7 +111,7 @@ internal AutorecoveringConnection CreateAutorecoveringConnection(TimeSpan interv
106111
AutomaticRecoveryEnabled = true,
107112
NetworkRecoveryInterval = interval
108113
};
109-
return (AutorecoveringConnection)cf.CreateConnection($"UNIT_CONN:{Guid.NewGuid()}");
114+
return (AutorecoveringConnection)cf.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}");
110115
}
111116

112117
internal AutorecoveringConnection CreateAutorecoveringConnection(TimeSpan interval, IList<string> hostnames)
@@ -119,7 +124,7 @@ internal AutorecoveringConnection CreateAutorecoveringConnection(TimeSpan interv
119124
RequestedConnectionTimeout = TimeSpan.FromSeconds(1),
120125
NetworkRecoveryInterval = interval
121126
};
122-
return (AutorecoveringConnection)cf.CreateConnection(hostnames, $"UNIT_CONN:{Guid.NewGuid()}");
127+
return (AutorecoveringConnection)cf.CreateConnection(hostnames, $"{_testDisplayName}:{Guid.NewGuid()}");
123128
}
124129

125130
internal AutorecoveringConnection CreateAutorecoveringConnection(IList<AmqpTcpEndpoint> endpoints)
@@ -132,7 +137,7 @@ internal AutorecoveringConnection CreateAutorecoveringConnection(IList<AmqpTcpEn
132137
RequestedConnectionTimeout = TimeSpan.FromSeconds(1),
133138
NetworkRecoveryInterval = RECOVERY_INTERVAL
134139
};
135-
return (AutorecoveringConnection)cf.CreateConnection(endpoints, $"UNIT_CONN:{Guid.NewGuid()}");
140+
return (AutorecoveringConnection)cf.CreateConnection(endpoints, $"{_testDisplayName}:{Guid.NewGuid()}");
136141
}
137142

138143
internal AutorecoveringConnection CreateAutorecoveringConnectionWithTopologyRecoveryDisabled()
@@ -143,7 +148,7 @@ internal AutorecoveringConnection CreateAutorecoveringConnectionWithTopologyReco
143148
TopologyRecoveryEnabled = false,
144149
NetworkRecoveryInterval = RECOVERY_INTERVAL
145150
};
146-
return (AutorecoveringConnection)cf.CreateConnection($"UNIT_CONN:{Guid.NewGuid()}");
151+
return (AutorecoveringConnection)cf.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}");
147152
}
148153

149154
internal IConnection CreateNonRecoveringConnection()
@@ -153,7 +158,7 @@ internal IConnection CreateNonRecoveringConnection()
153158
AutomaticRecoveryEnabled = false,
154159
TopologyRecoveryEnabled = false
155160
};
156-
return cf.CreateConnection($"UNIT_CONN:{Guid.NewGuid()}");
161+
return cf.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}");
157162
}
158163

159164
internal IConnection CreateConnectionWithContinuationTimeout(bool automaticRecoveryEnabled, TimeSpan continuationTimeout)
@@ -163,7 +168,7 @@ internal IConnection CreateConnectionWithContinuationTimeout(bool automaticRecov
163168
AutomaticRecoveryEnabled = automaticRecoveryEnabled,
164169
ContinuationTimeout = continuationTimeout
165170
};
166-
return cf.CreateConnection($"UNIT_CONN:{Guid.NewGuid()}");
171+
return cf.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}");
167172
}
168173

169174
//
@@ -177,7 +182,7 @@ internal void WithTemporaryAutorecoveringConnection(Action<AutorecoveringConnect
177182
AutomaticRecoveryEnabled = true
178183
};
179184

180-
var connection = (AutorecoveringConnection)factory.CreateConnection($"UNIT_CONN:{Guid.NewGuid()}");
185+
var connection = (AutorecoveringConnection)factory.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}");
181186
try
182187
{
183188
action(connection);

projects/Unit/TestAsyncConsumerExceptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public class TestAsyncConsumerExceptions : IntegrationFixture
4242
{
4343
private static Exception TestException = new Exception("oops");
4444

45+
public TestAsyncConsumerExceptions() : base()
46+
{
47+
}
48+
4549
protected void TestExceptionHandlingWith(IBasicConsumer consumer,
4650
Action<IModel, string, IBasicConsumer, string> action)
4751
{

projects/Unit/TestBasicGet.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ namespace RabbitMQ.Client.Unit
3838
[TestFixture]
3939
public class TestBasicGet : IntegrationFixture
4040
{
41+
public TestBasicGet() : base()
42+
{
43+
}
44+
4145
[Test]
4246
public void TestBasicGetWithClosedChannel()
4347
{

projects/Unit/TestBasicPublishBatch.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@
3535

3636
namespace RabbitMQ.Client.Unit
3737
{
38-
internal class TestBasicPublishBatch : IntegrationFixture
38+
public class TestBasicPublishBatch : IntegrationFixture
3939
{
40+
public TestBasicPublishBatch() : base()
41+
{
42+
}
43+
4044
[Test]
4145
public void TestBasicPublishBatchSend()
4246
{

projects/Unit/TestConcurrentAccessWithSharedConnection.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ namespace RabbitMQ.Client.Unit
4242
[TestFixture]
4343
public class TestConcurrentAccessWithSharedConnection : IntegrationFixture
4444
{
45-
4645
internal const int Threads = 32;
4746
internal CountdownEvent _latch;
4847
internal TimeSpan _completionTimeout = TimeSpan.FromSeconds(90);
4948

49+
public TestConcurrentAccessWithSharedConnection() : base()
50+
{
51+
}
52+
5053
[SetUp]
5154
public override void Init()
5255
{

projects/Unit/TestConfirmSelect.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
namespace RabbitMQ.Client.Unit
3535
{
3636
[TestFixture]
37-
public class TestConfirmSelect : IntegrationFixture {
37+
public class TestConfirmSelect : IntegrationFixture
38+
{
39+
public TestConfirmSelect() : base()
40+
{
41+
}
3842

3943
[Test]
4044
public void TestConfirmSelectIdempotency()

projects/Unit/TestConnectionBlocked.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ public class TestConnectionBlocked : IntegrationFixture
4444
private readonly object _lockObject = new object();
4545
private bool _notified;
4646

47+
public TestConnectionBlocked() : base()
48+
{
49+
}
50+
4751
public void HandleBlocked(object sender, ConnectionBlockedEventArgs args)
4852
{
4953
Unblock();
5054
}
5155

52-
5356
public void HandleUnblocked(object sender, EventArgs ea)
5457
{
5558
lock (_lockObject)

projects/Unit/TestConnectionFactoryContinuationTimeout.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@
3535
namespace RabbitMQ.Client.Unit
3636
{
3737
[TestFixture]
38-
internal class TestConnectionFactoryContinuationTimeout : IntegrationFixture
38+
public class TestConnectionFactoryContinuationTimeout : IntegrationFixture
3939
{
40+
public TestConnectionFactoryContinuationTimeout() : base()
41+
{
42+
}
43+
4044
[Test]
4145
public void TestConnectionFactoryContinuationTimeoutOnRecoveringConnection()
4246
{

projects/Unit/TestConnectionRecovery.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class TestConnectionRecovery : IntegrationFixture
5252
private readonly ushort _closeAtCount = 16;
5353
private string _queueName;
5454

55-
public TestConnectionRecovery()
55+
public TestConnectionRecovery() : base()
5656
{
5757
var rnd = new Random();
5858
_messageBody = new byte[4096];
@@ -68,10 +68,19 @@ public override void Init()
6868
Model.QueueDelete(_queueName);
6969
}
7070

71-
[TearDown]
72-
public void CleanUp()
71+
protected override void ReleaseResources()
7372
{
74-
Conn.Close();
73+
if (Model.IsOpen)
74+
{
75+
Model.Close();
76+
}
77+
78+
if (Conn.IsOpen)
79+
{
80+
Conn.Close();
81+
}
82+
83+
Unblock();
7584
}
7685

7786
[Test]
@@ -1095,11 +1104,6 @@ internal ManualResetEventSlim PrepareForShutdown(IConnection conn)
10951104
return latch;
10961105
}
10971106

1098-
protected override void ReleaseResources()
1099-
{
1100-
Unblock();
1101-
}
1102-
11031107
internal void RestartServerAndWaitForRecovery()
11041108
{
11051109
RestartServerAndWaitForRecovery((IAutorecoveringConnection)Conn);

projects/Unit/TestConnectionShutdown.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ namespace RabbitMQ.Client.Unit
4242
[TestFixture]
4343
public class TestConnectionShutdown : IntegrationFixture
4444
{
45+
public TestConnectionShutdown() : base()
46+
{
47+
}
48+
4549
[Test]
4650
public void TestCleanClosureWithSocketClosedOutOfBand()
4751
{

projects/Unit/TestConsumerCount.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@
3535

3636
namespace RabbitMQ.Client.Unit
3737
{
38-
internal class TestConsumerCount : IntegrationFixture
38+
[TestFixture]
39+
public class TestConsumerCount : IntegrationFixture
3940
{
41+
public TestConsumerCount() : base()
42+
{
43+
}
44+
4045
[Test]
4146
public void TestConsumerCountMethod()
4247
{

projects/Unit/TestConsumerExceptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ namespace RabbitMQ.Client.Unit
3939
[TestFixture]
4040
public class TestConsumerExceptions : IntegrationFixture
4141
{
42+
public TestConsumerExceptions() : base()
43+
{
44+
}
45+
4246
private class ConsumerFailingOnDelivery : DefaultBasicConsumer
4347
{
4448
public ConsumerFailingOnDelivery(IModel model) : base(model)

projects/Unit/TestConsumerOperationDispatch.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
namespace RabbitMQ.Client.Unit
4242
{
4343
[TestFixture]
44-
internal class TestConsumerOperationDispatch : IntegrationFixture
44+
public class TestConsumerOperationDispatch : IntegrationFixture
4545
{
4646
private readonly string _x = "dotnet.tests.consumer-operation-dispatch.fanout";
4747
private readonly List<IModel> _channels = new List<IModel>();
@@ -56,6 +56,10 @@ internal class TestConsumerOperationDispatch : IntegrationFixture
5656

5757
public static CountdownEvent counter = new CountdownEvent(Y);
5858

59+
public TestConsumerOperationDispatch() : base()
60+
{
61+
}
62+
5963
[TearDown]
6064
protected override void ReleaseResources()
6165
{

projects/Unit/TestEventingConsumer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@
3838
namespace RabbitMQ.Client.Unit
3939
{
4040
[TestFixture]
41-
public class TestEventingConsumer : IntegrationFixture {
41+
public class TestEventingConsumer : IntegrationFixture
42+
{
43+
public TestEventingConsumer() : base()
44+
{
45+
}
4246

4347
[Test]
4448
public void TestEventingConsumerRegistrationEvents()

projects/Unit/TestExceptionMessages.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ namespace RabbitMQ.Client.Unit
4040
[TestFixture]
4141
public class TestExceptionMessages : IntegrationFixture
4242
{
43+
public TestExceptionMessages() : base()
44+
{
45+
}
46+
4347
[Test]
4448
public void TestAlreadyClosedExceptionMessage()
4549
{

projects/Unit/TestExchangeDeclare.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@
3838
namespace RabbitMQ.Client.Unit
3939
{
4040
[TestFixture]
41-
public class TestExchangeDeclare : IntegrationFixture {
41+
public class TestExchangeDeclare : IntegrationFixture
42+
{
43+
public TestExchangeDeclare() : base()
44+
{
45+
}
4246

4347
[Test]
4448
[Category("RequireSMP")]

projects/Unit/TestExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ namespace RabbitMQ.Client.Unit
3838
[TestFixture]
3939
public class TestExtensions : IntegrationFixture
4040
{
41+
public TestExtensions() : base()
42+
{
43+
}
44+
4145
[Test]
4246
public void TestConfirmBarrier()
4347
{

projects/Unit/TestHeartbeats.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@
3838
namespace RabbitMQ.Client.Unit
3939
{
4040
[TestFixture]
41-
internal class TestHeartbeats : IntegrationFixture
41+
public class TestHeartbeats : IntegrationFixture
4242
{
4343
private readonly TimeSpan _heartbeatTimeout = TimeSpan.FromSeconds(2);
4444

45+
public TestHeartbeats() : base()
46+
{
47+
}
48+
4549
[Test, Category("LongRunning"), MaxTimeAttribute(35000)]
4650
public void TestThatHeartbeatWriterUsesConfigurableInterval()
4751
{

projects/Unit/TestInitialConnection.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ namespace RabbitMQ.Client.Unit
4040
[TestFixture]
4141
public class TestInitialConnection : IntegrationFixture
4242
{
43+
public TestInitialConnection() : base()
44+
{
45+
}
46+
4347
[Test]
4448
public void TestBasicConnectionRecoveryWithHostnameList()
4549
{

projects/Unit/TestInvalidAck.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
namespace RabbitMQ.Client.Unit
3737
{
3838
[TestFixture]
39-
public class TestInvalidAck : IntegrationFixture {
39+
public class TestInvalidAck : IntegrationFixture
40+
{
41+
public TestInvalidAck() : base()
42+
{
43+
}
4044

4145
[Test]
4246
public void TestAckWithUnknownConsumerTagAndMultipleFalse()

projects/Unit/TestMainLoop.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
namespace RabbitMQ.Client.Unit
4040
{
4141
[TestFixture]
42-
public class TestMainLoop : IntegrationFixture {
42+
public class TestMainLoop : IntegrationFixture
43+
{
44+
public TestMainLoop() : base()
45+
{
46+
}
4347

4448
private class FaultyConsumer : DefaultBasicConsumer
4549
{

0 commit comments

Comments
 (0)