Skip to content

Commit

Permalink
More thorough cleanup during unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed May 1, 2017
1 parent e2bd283 commit 641dc70
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 73 deletions.
4 changes: 3 additions & 1 deletion src/NetMQ.Tests/ActorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

namespace NetMQ.Tests
{
public class ActorTests
public class ActorTests : IClassFixture<CleanupAfterFixture>
{
public ActorTests() => NetMQConfig.Cleanup();

[Fact]
public void Simple()
{
Expand Down
3 changes: 3 additions & 0 deletions src/NetMQ.Tests/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using Xunit;

[assembly: CollectionBehavior(DisableTestParallelization = true)]
4 changes: 3 additions & 1 deletion src/NetMQ.Tests/BeaconTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
namespace NetMQ.Tests
{
[Trait("Category", "Beacon")]
public class BeaconTests
public class BeaconTests : IClassFixture<CleanupAfterFixture>
{
private static readonly TimeSpan s_publishInterval = TimeSpan.FromMilliseconds(100);

public BeaconTests() => NetMQConfig.Cleanup();

[Fact]
public void SimplePublishSubscribe()
{
Expand Down
11 changes: 11 additions & 0 deletions src/NetMQ.Tests/CleanupAfterFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using JetBrains.Annotations;

namespace NetMQ.Tests
{
[UsedImplicitly]
public sealed class CleanupAfterFixture : IDisposable
{
public void Dispose() => NetMQConfig.Cleanup();
}
}
21 changes: 11 additions & 10 deletions src/NetMQ.Tests/CleanupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

namespace NetMQ.Tests
{
public class CleanupTests
public class CleanupTests : IClassFixture<CleanupAfterFixture>
{
public CleanupTests() => NetMQConfig.Cleanup();

[Fact]
public void Block()
{
Expand All @@ -18,15 +20,14 @@ public void Block()
{
// Sending a lot of messages
client.Options.SendHighWatermark = count;

for (int i = 0; i < count; i++)
{
client.SendFrame("Hello");
}
}

Stopwatch stopwatch = Stopwatch.StartNew();
var stopwatch = Stopwatch.StartNew();

NetMQConfig.Cleanup(block: true);
stopwatch.Stop();

Assert.True(stopwatch.ElapsedMilliseconds > 500);
}
Expand All @@ -42,23 +43,23 @@ public void NoBlock()
{
// Sending a lot of messages
client.Options.SendHighWatermark = count;

for (int i = 0; i < count; i++)
{
client.SendFrame("Hello");
}
}

Stopwatch stopwatch = Stopwatch.StartNew();
var stopwatch = Stopwatch.StartNew();

NetMQConfig.Cleanup(block: false);
stopwatch.Stop();

Assert.True(stopwatch.ElapsedMilliseconds < 500);
}

[Fact]
public void NoBlockNoDispose()
{
var client = new DealerSocket(">tcp://localhost:5557");
new DealerSocket(">tcp://localhost:5557");

NetMQConfig.Cleanup(block: false);
}
}
Expand Down
22 changes: 0 additions & 22 deletions src/NetMQ.Tests/NetMQConfigFixture.cs

This file was deleted.

6 changes: 4 additions & 2 deletions src/NetMQ.Tests/NetMQMonitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
namespace NetMQ.Tests
{
[Trait("Category", "Monitor")]
public class NetMQMonitorTests
public class NetMQMonitorTests : IClassFixture<CleanupAfterFixture>
{
public NetMQMonitorTests() => NetMQConfig.Cleanup();

[Fact]
public void Monitoring()
{
using (var rep = new ResponseSocket())
using (var req = new RequestSocket())
using (var monitor = new NetMQMonitor(rep, $"inproc://rep.inproc", SocketEvents.Accepted | SocketEvents.Listening))
using (var monitor = new NetMQMonitor(rep, "inproc://rep.inproc", SocketEvents.Accepted | SocketEvents.Listening))
{
var listening = false;
var accepted = false;
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ.Tests/NetMQPollerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
namespace NetMQ.Tests
{
[Trait("Category", "Poller")]
public class NetMQPollerTest
public class NetMQPollerTest : IClassFixture<CleanupAfterFixture>
{
public NetMQPollerTest() => NetMQConfig.Cleanup();

#region Socket polling tests

[Fact]
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ.Tests/NetMQProactorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace NetMQ.Tests
{
public class NetMQProactorTests
public class NetMQProactorTests : IClassFixture<CleanupAfterFixture>
{
public NetMQProactorTests() => NetMQConfig.Cleanup();

[Fact]
public void ReceiveMessage()
{
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ.Tests/NetMQQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

namespace NetMQ.Tests
{
public class NetMQQueueTests
public class NetMQQueueTests : IClassFixture<CleanupAfterFixture>
{
public NetMQQueueTests() => NetMQConfig.Cleanup();

[Fact]
public void EnqueueDequeue()
{
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ.Tests/PgmTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ namespace NetMQ.Tests
// Note: The 224.0.0.1 is the IPv4 All Hosts multicast group which addresses all hosts on the same network segment.

[Trait("Category", "PGM")]
public class PgmTests
public class PgmTests : IClassFixture<CleanupAfterFixture>
{
public PgmTests() => NetMQConfig.Cleanup();

[Fact(Skip = "Requires MSMQ for PGM sockets")]
public void SimplePubSub()
{
Expand Down
5 changes: 4 additions & 1 deletion src/NetMQ.Tests/ProxyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

namespace NetMQ.Tests
{
public class ProxyTests : IClassFixture<NetMQConfigFixture>
public class ProxyTests : IClassFixture<CleanupAfterFixture>
{
/// <summary>Clean up before each test.</summary>
public ProxyTests() => NetMQConfig.Cleanup();

[Fact]
public void SendAndReceive()
{
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ.Tests/PubSubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

namespace NetMQ.Tests
{
public class PubSubTests : IClassFixture<NetMQConfigFixture>
public class PubSubTests : IClassFixture<CleanupAfterFixture>
{
public PubSubTests() => NetMQConfig.Cleanup();

[Fact]
public void TopicPubSub()
{
Expand Down
8 changes: 5 additions & 3 deletions src/NetMQ.Tests/PushPullTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

namespace NetMQ.Tests
{
public class PushPullTests
public class PushPullTests : IClassFixture<CleanupAfterFixture>
{
public PushPullTests() => NetMQConfig.Cleanup();

[Fact]
public void SimplePushPull()
{
{
using (var pullSocket = new PullSocket())
using (var pushSocket = new PushSocket())
{
Expand All @@ -22,7 +24,7 @@ public void SimplePushPull()

[Fact]
public void EmptyMessage()
{
{
using (var pullSocket = new PullSocket())
using (var pushSocket = new PushSocket())
{
Expand Down
6 changes: 4 additions & 2 deletions src/NetMQ.Tests/ReqRepTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

namespace NetMQ.Tests
{
public class ReqRepTests
public class ReqRepTests : IClassFixture<CleanupAfterFixture>
{
public ReqRepTests() => NetMQConfig.Cleanup();

[Theory]
[InlineData("tcp://localhost")]
[InlineData("tcp://127.0.0.1")]
Expand All @@ -28,7 +30,7 @@ public void SimpleReqRep(string address)

[Fact]
public void SendingTwoRequestsInARow()
{
{
using (var rep = new ResponseSocket())
using (var req = new RequestSocket())
{
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ.Tests/RequestWithRetryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

namespace NetMQ.Tests
{
public class RequestWithRetryTests : IClassFixture<NetMQConfigFixture>
public class RequestWithRetryTests : IClassFixture<CleanupAfterFixture>
{
public RequestWithRetryTests() => NetMQConfig.Cleanup();

[Fact]
public void RequestResponseMultipartMessageWithRetrySucceedsFirstTry()
{
Expand Down
8 changes: 5 additions & 3 deletions src/NetMQ.Tests/RouterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

namespace NetMQ.Tests
{
public class RouterTests
public class RouterTests : IClassFixture<CleanupAfterFixture>
{
public RouterTests() => NetMQConfig.Cleanup();

[Fact]
public void Mandatory()
{
Expand Down Expand Up @@ -60,7 +62,7 @@ public void TwoMessagesFromRouterToDealer()
var cnt = 0;
client.ReceiveReady += (sender, e) =>
{
e.Socket.ReceiveMultipartStrings();
e.Socket.ReceiveMultipartStrings();
cnt++;
if (cnt == 2)
{
Expand Down Expand Up @@ -110,7 +112,7 @@ public void Handover()
dealer2.Options.Identity = Encoding.ASCII.GetBytes("ID");
dealer2.Connect("inproc://127.0.0.1:5555");

// We have new peer which should take over, however we are still reading a message
// We have new peer which should take over, however we are still reading a message
var message = router.ReceiveFrameString();
Assert.Equal("Hello", message);
message = router.ReceiveFrameString();
Expand Down
18 changes: 0 additions & 18 deletions src/NetMQ.Tests/Setup.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/NetMQ.Tests/SocketOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace NetMQ.Tests
{
public class SocketOptionsTests
public class SocketOptionsTests : IClassFixture<CleanupAfterFixture>
{
public SocketOptionsTests() => NetMQConfig.Cleanup();

[Fact]
public void DefaultValues()
{
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ.Tests/SocketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

namespace NetMQ.Tests
{
public class SocketTests : IClassFixture<NetMQConfigFixture>
public class SocketTests : IClassFixture<CleanupAfterFixture>
{
public SocketTests() => NetMQConfig.Cleanup();

[Fact]
public void CheckTryReceive()
{
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ.Tests/StreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace NetMQ.Tests
{
public class StreamTests
public class StreamTests : IClassFixture<CleanupAfterFixture>
{
public StreamTests() => NetMQConfig.Cleanup();

[Fact]
public void StreamToStream()
{
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ.Tests/XPubSubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

namespace NetMQ.Tests
{
public class XPubSubTests
public class XPubSubTests : IClassFixture<CleanupAfterFixture>
{
public XPubSubTests() => NetMQConfig.Cleanup();

[Fact]
public void TopicPubSub()
{
Expand Down

0 comments on commit 641dc70

Please sign in to comment.