public void PubSub_Should_Not_Crash_If_No_Thread_Sleep()
        {
            NUnitUtils.PrintTestName();
            var swAll = Stopwatch.StartNew();

            using (var pub = new PublisherSocket())
            {
                using (var sub = new SubscriberSocket())
                {
                    var freePort = NUnitUtils.TcpPortFree();
                    pub.Bind("tcp://127.0.0.1:" + freePort);
                    sub.Connect("tcp://127.0.0.1:" + freePort);

                    sub.Subscribe("*");

                    var sw = Stopwatch.StartNew();
                    {
                        for (var i = 0; i < 50; i++)
                        {
                            pub.SendFrame("*"); // Ping.

                            Console.Write("*");
                            string topic;
                            var gotTopic = sub.TryReceiveFrameString(TimeSpan.FromMilliseconds(100), out topic);
                            string ping;
                            var gotPing = sub.TryReceiveFrameString(TimeSpan.FromMilliseconds(100), out ping);
                            if (gotTopic)
                            {
                                Console.Write("\n");
                                break;
                            }
                        }
                    }
                    Console.WriteLine("Connected in {0} ms.", sw.ElapsedMilliseconds);
                }
            }
            NUnitUtils.PrintElapsedTime(swAll.Elapsed);
        }
        public void Test_Two_Subscribers()
        {
            NUnitUtils.PrintTestName();
            var sw = Stopwatch.StartNew();

            using (var pub = new PublisherSocket())
            {
                using (var sub1 = new SubscriberSocket())
                {
                    using (var sub2 = new SubscriberSocket())
                    {
                        var freePort = NUnitUtils.TcpPortFree();
                        pub.Bind("tcp://127.0.0.1:" + freePort);
                        sub1.Connect("tcp://127.0.0.1:" + freePort);
                        sub1.Subscribe("A");
                        sub2.Connect("tcp://127.0.0.1:" + freePort);
                        sub2.Subscribe("B");

                        Thread.Sleep(500);

                        var swInner = Stopwatch.StartNew();
                        {
                            pub.SendFrame("A\n"); // Ping.
                            {
                                string topic;
                                var pass1 = sub1.TryReceiveFrameString(TimeSpan.FromMilliseconds(250), out topic);
                                if (pass1)
                                {
                                    Console.Write(topic);
                                }
                                else
                                {
                                    Assert.Fail();
                                }
                            }
                            pub.SendFrame("B\n"); // Ping.
                            {
                                string topic;
                                var pass2 = sub2.TryReceiveFrameString(TimeSpan.FromMilliseconds(250), out topic);
                                if (pass2)
                                {
                                    Console.Write(topic);
                                }
                                else
                                {
                                    Assert.Fail();
                                }
                            }
                        }
                        Console.WriteLine("Connected in {0} ms.", swInner.ElapsedMilliseconds);
                    }
                }
            }

            NUnitUtils.PrintElapsedTime(sw.Elapsed);
        }