Permalink
Browse files

Restrict monitor events in tests.

This prevents hanging event messages from blowing up context objects
during test disposal.
  • Loading branch information...
1 parent 9e8e863 commit 884dfcf62678db4883e96c2b99988434d2666b35 @jgoz jgoz committed Nov 12, 2012
@@ -15,6 +15,8 @@ public abstract class UsingMonitor
protected ZmqMonitor ReqMonitor;
protected ZmqMonitor RepMonitor;
+ protected MonitorEvents ReqEvents;
+ protected MonitorEvents RepEvents;
protected Thread ReqThread;
protected Thread RepThread;
protected ZmqSocket Req;
@@ -33,17 +35,17 @@ public void Initialize()
RepMonitor = RepContext.CreateMonitorSocket(RepEndpoint);
Req = ReqContext.CreateSocket(SocketType.REQ);
Rep = RepContext.CreateSocket(SocketType.REP);
- Req.Monitor(ReqEndpoint);
- Rep.Monitor(RepEndpoint);
+ Req.Monitor(ReqEndpoint, ReqEvents);
+ Rep.Monitor(RepEndpoint, RepEvents);
EventRecorded = new ManualResetEvent(false);
ReqThread = new Thread(ReqMonitor.Start);
RepThread = new Thread(RepMonitor.Start);
- ReqThread.Start();
- RepThread.Start();
-
Fired = false;
Address = null;
+
+ ReqThread.Start();
+ RepThread.Start();
}
[TestFixtureTearDown]
@@ -2,12 +2,18 @@
{
using System;
using NUnit.Framework;
+ using ZeroMQ.Monitoring;
[TestFixture]
public class MonitorTests
{
public class WhenMonitoringListeningEvent : UsingMonitorFd
{
+ public WhenMonitoringListeningEvent()
+ {
+ RepEvents = MonitorEvents.Listening;
+ }
+
[TestFixtureSetUp]
public void SetUp()
{
@@ -41,6 +47,11 @@ public void ShouldReturnASocketPointer()
public class WhenMonitoringAcceptedEvent : UsingMonitorFd
{
+ public WhenMonitoringAcceptedEvent()
+ {
+ RepEvents = MonitorEvents.Accepted;
+ }
+
[TestFixtureSetUp]
public void SetUp()
{
@@ -75,6 +86,11 @@ public void ShouldReturnASocketPointer()
public class WhenMonitoringAcceptedEventBeforeAConnectionIsMade : UsingMonitorFd
{
+ public WhenMonitoringAcceptedEventBeforeAConnectionIsMade()
+ {
+ RepEvents = MonitorEvents.Accepted;
+ }
+
[TestFixtureSetUp]
public void SetUp()
{
@@ -92,6 +108,11 @@ public void ShouldNotFireTheAcceptedEvent()
public class WhenMonitoringConnectedEvent : UsingMonitorFd
{
+ public WhenMonitoringConnectedEvent()
+ {
+ ReqEvents = MonitorEvents.Connected;
+ }
+
[TestFixtureSetUp]
public void SetUp()
{
@@ -126,6 +147,11 @@ public void ShouldReturnASocketPointer()
public class WhenMonitoringClosedEvent : UsingMonitorFd
{
+ public WhenMonitoringClosedEvent()
+ {
+ RepEvents = MonitorEvents.Closed;
+ }
+
[TestFixtureSetUp]
public void SetUp()
{
@@ -150,6 +150,7 @@ public void Start()
}
Marshal.FreeHGlobal(ptr);
+ _socket.Disconnect(_endpoint);
}
/// <summary>

0 comments on commit 884dfcf

Please sign in to comment.