Skip to content

Commit e41d31d

Browse files
Merge pull request #207 from rabbitmq/rabbitmq-dotnet-client-206
AppVeyor dotnetcore build, test and packaging
2 parents e181876 + fc0a4a2 commit e41d31d

File tree

8 files changed

+117
-85
lines changed

8 files changed

+117
-85
lines changed

appveyor.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ install:
3232
before_build:
3333

3434
build_script:
35-
- ps: .\fake.bat GenerateApi
36-
- ps: dotnet restore "projects\client\RabbitMQ.Client"
37-
- ps: dotnet build "projects\client\RabbitMQ.Client"
38-
- ps: dotnet pack "projects\client\RabbitMQ.Client" -c Release --version-suffix=build-$env:APPVEYOR_BUILD_NUMBER
35+
- cmd: .\build.bat
36+
- cmd: .\run-test.bat
37+
- ps: |
38+
$suffix = Get-Date -format "yyyyMMddhhss"
39+
Write-Host $suffix
40+
dotnet pack "projects\client\RabbitMQ.Client" -c Release --version-suffix=ci-$suffix
3941
4042
test: off
4143

projects/client/Unit/src/unit/Fixtures.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ protected List<ConnectionInfo> ListConnections()
564564
return new ConnectionInfo(columns[0], Convert.ToUInt32(columns[1].Trim()));
565565
}).ToList();
566566
}
567-
catch (Exception ex)
567+
catch (Exception)
568568
{
569569
Console.WriteLine("Bad response from rabbitmqctl list_connections -q pid peer_port:" + Environment.NewLine + stdout);
570570
throw;

projects/client/Unit/src/unit/TestConnectionFactory.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void TestCreateConnectionUsesSpecifiedPort()
7979
cf.Port = 1234;
8080
Assert.That(() =>
8181
{
82-
using(var conn = cf.CreateConnection());
82+
using(var conn = cf.CreateConnection()) {}
8383
}, Throws.TypeOf<BrokerUnreachableException>());
8484
}
8585

@@ -92,7 +92,7 @@ public void TestCreateConnectionWithClientProvidedNameUsesSpecifiedPort()
9292
cf.Port = 1234;
9393
Assert.That(() =>
9494
{
95-
using(var conn = cf.CreateConnection("some_name"));
95+
using(var conn = cf.CreateConnection("some_name")) {}
9696
}, Throws.TypeOf<BrokerUnreachableException>());
9797
}
9898

@@ -125,7 +125,9 @@ public void TestCreateConnectionUsesDefaultPort()
125125
var cf = new ConnectionFactory();
126126
cf.AutomaticRecoveryEnabled = true;
127127
cf.HostName = "localhost";
128-
using(var conn = cf.CreateConnection());
128+
using(var conn = cf.CreateConnection()){
129+
Assert.AreEqual(5672, conn.Endpoint.Port);
130+
}
129131
}
130132

131133
[Test]
@@ -149,7 +151,7 @@ public void TestCreateConnectionWithAutoRecoveryUsesAmqpTcpEndpoint()
149151
cf.HostName = "not_localhost";
150152
cf.Port = 1234 ;
151153
var ep = new AmqpTcpEndpoint("localhost");
152-
using(var conn = cf.CreateConnection(new System.Collections.Generic.List<AmqpTcpEndpoint> { ep }));
154+
using(var conn = cf.CreateConnection(new System.Collections.Generic.List<AmqpTcpEndpoint> { ep })) {}
153155
}
154156

155157
[Test]
@@ -160,7 +162,7 @@ public void TestCreateConnectionWithAutoRecoveryUsesInvalidAmqpTcpEndpoint()
160162
var ep = new AmqpTcpEndpoint("localhost", 1234);
161163
Assert.That(() =>
162164
{
163-
using(var conn = cf.CreateConnection(new System.Collections.Generic.List<AmqpTcpEndpoint> { ep }));
165+
using(var conn = cf.CreateConnection(new System.Collections.Generic.List<AmqpTcpEndpoint> { ep })){}
164166
}, Throws.TypeOf<BrokerUnreachableException>());
165167
}
166168

@@ -171,7 +173,7 @@ public void TestCreateConnectionUsesAmqpTcpEndpoint()
171173
cf.HostName = "not_localhost";
172174
cf.Port = 1234 ;
173175
var ep = new AmqpTcpEndpoint("localhost");
174-
using(var conn = cf.CreateConnection(new System.Collections.Generic.List<AmqpTcpEndpoint> { ep }));
176+
using(var conn = cf.CreateConnection(new System.Collections.Generic.List<AmqpTcpEndpoint> { ep })) {}
175177
}
176178

177179
[Test]
@@ -181,7 +183,7 @@ public void TestCreateConnectionUsesInvalidAmqpTcpEndpoint()
181183
var ep = new AmqpTcpEndpoint("localhost", 1234);
182184
Assert.That(() =>
183185
{
184-
using(var conn = cf.CreateConnection(new System.Collections.Generic.List<AmqpTcpEndpoint> { ep }));
186+
using(var conn = cf.CreateConnection(new System.Collections.Generic.List<AmqpTcpEndpoint> { ep })) {}
185187
}, Throws.TypeOf<BrokerUnreachableException>());
186188
}
187189
}

projects/client/Unit/src/unit/TestConnectionRecovery.cs

Lines changed: 90 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,36 @@
4747
using System.Collections.Generic;
4848
using System.Threading;
4949

50-
#pragma warning disable 0168
50+
#pragma warning disable 0618
5151

5252
namespace RabbitMQ.Client.Unit
5353
{
54+
class DisposableConnection : IDisposable
55+
{
56+
public DisposableConnection(AutorecoveringConnection c)
57+
{
58+
this.Connection = c;
59+
}
60+
61+
public AutorecoveringConnection Connection {get; private set;}
62+
63+
public void Dispose()
64+
{
65+
this.Connection.Close();
66+
}
67+
}
5468
[TestFixture]
5569
public class TestConnectionRecovery : IntegrationFixture
5670
{
71+
private DisposableConnection CreateWrappedAutorecoveringConnection()
72+
{
73+
return new DisposableConnection(CreateAutorecoveringConnection());
74+
}
75+
private DisposableConnection CreateWrappedAutorecoveringConnection(IList<string> hostnames)
76+
{
77+
return new DisposableConnection(CreateAutorecoveringConnection(hostnames));
78+
}
79+
5780
[SetUp]
5881
public override void Init()
5982
{
@@ -97,52 +120,56 @@ public void TestBasicConnectionRecovery()
97120
[Test]
98121
public void TestBasicConnectionRecoveryWithHostnameList()
99122
{
100-
var c = CreateAutorecoveringConnection(new List<string> { "127.0.0.1", "localhost" });
101-
Assert.IsTrue(c.IsOpen);
102-
CloseAndWaitForRecovery(c);
103-
Assert.IsTrue(c.IsOpen);
104-
c.Close();
123+
using(var c = CreateAutorecoveringConnection(new List<string> { "127.0.0.1", "localhost" }))
124+
{
125+
Assert.IsTrue(c.IsOpen);
126+
CloseAndWaitForRecovery(c);
127+
Assert.IsTrue(c.IsOpen);
128+
}
105129
}
106130

107131
[Test]
108132
public void TestBasicConnectionRecoveryWithHostnameListAndUnreachableHosts()
109133
{
110-
var c = CreateAutorecoveringConnection(new List<string> { "191.72.44.22", "127.0.0.1", "localhost" });
111-
Assert.IsTrue(c.IsOpen);
112-
CloseAndWaitForRecovery(c);
113-
Assert.IsTrue(c.IsOpen);
114-
c.Close();
134+
using(var c = CreateAutorecoveringConnection(new List<string> { "191.72.44.22", "127.0.0.1", "localhost" }))
135+
{
136+
Assert.IsTrue(c.IsOpen);
137+
CloseAndWaitForRecovery(c);
138+
Assert.IsTrue(c.IsOpen);
139+
}
115140
}
116141

117142
[Test]
118143
public void TestBasicConnectionRecoveryWithEndpointList()
119144
{
120-
var c = CreateAutorecoveringConnection(
145+
using(var c = CreateAutorecoveringConnection(
121146
new List<AmqpTcpEndpoint>
122147
{
123148
new AmqpTcpEndpoint("127.0.0.1"),
124149
new AmqpTcpEndpoint("localhost")
125-
});
126-
Assert.IsTrue(c.IsOpen);
127-
CloseAndWaitForRecovery(c);
128-
Assert.IsTrue(c.IsOpen);
129-
c.Close();
150+
}))
151+
{
152+
Assert.IsTrue(c.IsOpen);
153+
CloseAndWaitForRecovery(c);
154+
Assert.IsTrue(c.IsOpen);
155+
}
130156
}
131157

132158
[Test]
133159
public void TestBasicConnectionRecoveryWithEndpointListAndUnreachableHosts()
134160
{
135-
var c = CreateAutorecoveringConnection(
161+
using(var c = CreateAutorecoveringConnection(
136162
new List<AmqpTcpEndpoint>
137163
{
138164
new AmqpTcpEndpoint("191.72.44.22"),
139165
new AmqpTcpEndpoint("127.0.0.1"),
140166
new AmqpTcpEndpoint("localhost")
141-
});
142-
Assert.IsTrue(c.IsOpen);
143-
CloseAndWaitForRecovery(c);
144-
Assert.IsTrue(c.IsOpen);
145-
c.Close();
167+
}))
168+
{
169+
Assert.IsTrue(c.IsOpen);
170+
CloseAndWaitForRecovery(c);
171+
Assert.IsTrue(c.IsOpen);
172+
}
146173
}
147174

148175
[Test]
@@ -239,57 +266,59 @@ public void TestClientNamedQueueRecoveryOnServerRestart()
239266
[Test]
240267
public void TestConsumerWorkServiceRecovery()
241268
{
242-
AutorecoveringConnection c = CreateAutorecoveringConnection();
243-
IModel m = c.CreateModel();
244-
string q = m.QueueDeclare("dotnet-client.recovery.consumer_work_pool1",
245-
false, false, false, null).QueueName;
246-
var cons = new EventingBasicConsumer(m);
247-
m.BasicConsume(q, true, cons);
248-
AssertConsumerCount(m, q, 1);
269+
using(var c = CreateAutorecoveringConnection())
270+
{
271+
IModel m = c.CreateModel();
272+
string q = m.QueueDeclare("dotnet-client.recovery.consumer_work_pool1",
273+
false, false, false, null).QueueName;
274+
var cons = new EventingBasicConsumer(m);
275+
m.BasicConsume(q, true, cons);
276+
AssertConsumerCount(m, q, 1);
249277

250-
CloseAndWaitForRecovery(c);
278+
CloseAndWaitForRecovery(c);
251279

252-
Assert.IsTrue(m.IsOpen);
253-
var latch = new ManualResetEvent(false);
254-
cons.Received += (s, args) => latch.Set();
280+
Assert.IsTrue(m.IsOpen);
281+
var latch = new ManualResetEvent(false);
282+
cons.Received += (s, args) => latch.Set();
255283

256-
m.BasicPublish("", q, null, encoding.GetBytes("msg"));
257-
Wait(latch);
284+
m.BasicPublish("", q, null, encoding.GetBytes("msg"));
285+
Wait(latch);
258286

259-
m.QueueDelete(q);
260-
c.Close();
287+
m.QueueDelete(q);
288+
}
261289
}
262290

263291
[Test]
264292
public void TestConsumerRecoveryOnClientNamedQueueWithOneRecovery()
265293
{
266-
AutorecoveringConnection c = CreateAutorecoveringConnection();
267-
IModel m = c.CreateModel();
268-
string q = m.QueueDeclare("dotnet-client.recovery.queue1",
269-
false, false, false, null).QueueName;
270-
var cons = new EventingBasicConsumer(m);
271-
m.BasicConsume(q, true, cons);
272-
AssertConsumerCount(m, q, 1);
294+
using (var c = CreateAutorecoveringConnection())
295+
{
296+
IModel m = c.CreateModel();
297+
string q = m.QueueDeclare("dotnet-client.recovery.queue1",
298+
false, false, false, null).QueueName;
299+
var cons = new EventingBasicConsumer(m);
300+
m.BasicConsume(q, true, cons);
301+
AssertConsumerCount(m, q, 1);
273302

274-
string latestName = null;
303+
string latestName = null;
275304

276-
c.QueueNameChangeAfterRecovery += (source, ea) => { latestName = ea.NameAfter; };
305+
c.QueueNameChangeAfterRecovery += (source, ea) => { latestName = ea.NameAfter; };
277306

278-
CloseAndWaitForRecovery(c);
279-
AssertConsumerCount(m, latestName, 1);
280-
CloseAndWaitForRecovery(c);
281-
AssertConsumerCount(m, latestName, 1);
282-
CloseAndWaitForRecovery(c);
283-
AssertConsumerCount(m, latestName, 1);
307+
CloseAndWaitForRecovery(c);
308+
AssertConsumerCount(m, latestName, 1);
309+
CloseAndWaitForRecovery(c);
310+
AssertConsumerCount(m, latestName, 1);
311+
CloseAndWaitForRecovery(c);
312+
AssertConsumerCount(m, latestName, 1);
284313

285-
var latch = new ManualResetEvent(false);
286-
cons.Received += (s, args) => latch.Set();
314+
var latch = new ManualResetEvent(false);
315+
cons.Received += (s, args) => latch.Set();
287316

288-
m.BasicPublish("", q, null, encoding.GetBytes("msg"));
289-
Wait(latch);
317+
m.BasicPublish("", q, null, encoding.GetBytes("msg"));
318+
Wait(latch);
290319

291-
m.QueueDelete(q);
292-
c.Close();
320+
m.QueueDelete(q);
321+
}
293322
}
294323

295324
[Test]
@@ -327,7 +356,7 @@ public void TestCreateModelOnClosedAutorecoveringConnectionDoesNotHang()
327356
c.CreateModel();
328357
Assert.Fail("Expected an exception");
329358
}
330-
catch (AlreadyClosedException ace)
359+
catch (AlreadyClosedException)
331360
{
332361
// expected
333362
}
@@ -604,7 +633,7 @@ public void TestRecoveryWithTopologyDisabled()
604633
ch.QueueDeclarePassive(s);
605634
Assert.Fail("Expected an exception");
606635
}
607-
catch (OperationInterruptedException e)
636+
catch (OperationInterruptedException)
608637
{
609638
// expected
610639
}

projects/client/Unit/src/unit/TestHeartbeats.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
//---------------------------------------------------------------------------
4040

4141
using NUnit.Framework;
42-
using RabbitMQ.Client.Impl;
4342
using System;
4443
using System.Collections.Generic;
4544
using System.Threading;
@@ -107,7 +106,6 @@ public void TestHundredsOfConnectionsWithRandomHeartbeatInterval()
107106
var conn = cf.CreateConnection();
108107
xs.Add(conn);
109108
var ch = conn.CreateModel();
110-
bool wasShutdown = false;
111109

112110
conn.ConnectionShutdown += (sender, evt) =>
113111
{

projects/client/Unit/src/unit/TestRecoverAfterCancel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
using RabbitMQ.Client.Events;
5151
using RabbitMQ.Util;
5252

53+
#pragma warning disable 0618
54+
5355
namespace RabbitMQ.Client.Unit
5456
{
5557
[TestFixture]

run-test.bat

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@ECHO OFF
22

3-
dotnet restore .\projects\client\RabbitMQ.Client
4-
dotnet build .\projects\client\RabbitMQ.Client
5-
dotnet restore .\projects\client\Unit
6-
dotnet build .\projects\client\Unit
7-
dotnet restore .\projects\client\Unit.Runner
8-
cd .\projects\client\Unit.Runner
9-
dotnet run
3+
dotnet restore .\projects\client\RabbitMQ.Client || exit /b
4+
dotnet build .\projects\client\RabbitMQ.Client || exit /b
5+
dotnet restore .\projects\client\Unit || exit /b
6+
dotnet build .\projects\client\Unit || exit /b
7+
CD .\projects\client\Unit
8+
dotnet test -f netcoreapp1.0 --where="cat != RequireSMP & cat != LongRunning & cat != GCTest"
9+
CD ..\..\..

run-test.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ dotnet restore ./projects/client/RabbitMQ.Client
66
dotnet build ./projects/client/RabbitMQ.Client
77
dotnet restore ./projects/client/Unit
88
dotnet build ./projects/client/Unit
9-
dotnet restore ./projects/client/Unit.Runner
10-
cd ./projects/client/Unit.Runner
11-
dotnet run
9+
cd ./projects/client/Unit
10+
dotnet test -f netcoreapp1.0 --where='cat != RequireSMP & cat != LongRunning & cat != GCTest'
1211

1312

0 commit comments

Comments
 (0)