Ejemplo n.º 1
0
        public void MonitorDisposeProperlyWhenDisposedAfterMonitoredTcpSocket()
        {
            // The bug:
            // Given we monitor a netmq tcp socket
            // Given we disposed of the monitored socket first
            // When we dispose of the monitor
            // Then our monitor is Faulted with a EndpointNotFoundException
            // And monitor can't be stopped or disposed

            using (var theContext = NetMQContext.Create())
            using (var resSocket = theContext.CreateResponseSocket())
            {
                NetMQMonitor monitor;
                using (var reqSocket = theContext.CreateRequestSocket())
                {
                    monitor = new NetMQMonitor(theContext, reqSocket, "inproc://#monitor", SocketEvent.All);
                    Task.Factory.StartNew(() => monitor.Start());

                    //The bug is only occurring when monitor a tcp socket
                    var port = resSocket.BindRandomPort("tcp://127.0.0.1");
                    reqSocket.Connect("tcp://127.0.0.1:" + port);

                    reqSocket.Send("question");
                    Assert.That(resSocket.ReceiveString(), Is.EqualTo("question"));
                    resSocket.Send("response");
                    Assert.That(reqSocket.ReceiveString(), Is.EqualTo("response"));
                }
                Thread.Sleep(100);
                // Monitor.Dispose should complete
                var completed = Task.Factory.StartNew(() => monitor.Dispose()).Wait(1000);
                Assert.That(completed, Is.True);
            }
            //Note: If this test fails, it will hang because the context Dispose will block
        }
Ejemplo n.º 2
0
        public void MonitorDisposeProperlyWhenDisposedAfterMonitoredTcpSocket()
        {
            // The bug:
            // Given we monitor a netmq tcp socket
            // Given we disposed of the monitored socket first
            // When we dispose of the monitor
            // Then our monitor is Faulted with a EndpointNotFoundException
            // And monitor can't be stopped or disposed

            using (var theContext = NetMQContext.Create())
                using (var resSocket = theContext.CreateResponseSocket())
                {
                    NetMQMonitor monitor;
                    using (var reqSocket = theContext.CreateRequestSocket())
                    {
                        monitor = new NetMQMonitor(theContext, reqSocket, "inproc://#monitor", SocketEvent.All);
                        Task.Factory.StartNew(() => monitor.Start());

                        //The bug is only occurring when monitor a tcp socket
                        var port = resSocket.BindRandomPort("tcp://127.0.0.1");
                        reqSocket.Connect("tcp://127.0.0.1:" + port);

                        reqSocket.Send("question");
                        Assert.That(resSocket.ReceiveFrameString(), Is.EqualTo("question"));
                        resSocket.Send("response");
                        Assert.That(reqSocket.ReceiveFrameString(), Is.EqualTo("response"));
                    }
                    Thread.Sleep(100);
                    // Monitor.Dispose should complete
                    var completed = Task.Factory.StartNew(() => monitor.Dispose()).Wait(1000);
                    Assert.That(completed, Is.True);
                }
            //Note: If this test fails, it will hang because the context Dispose will block
        }