예제 #1
0
        public void TestChannelNamedInstance()
        {
            int ch1count = 0, ch2count = 0;

            using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel))
                using (IpcEventChannel ch2 = new IpcEventChannel(_registrar, _channel))
                    using (IpcEventChannel sender = new IpcEventChannel(_registrar, _channel))
                    {
                        ch1.StartListening("ch1");
                        ch2.StartListening("ch2");
                        sender.EnableAsyncSend();

                        ch1["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e)
                        { ch1count++; };
                        ch2["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e)
                        { ch2count++; };

                        for (int i = 0; i < 1000; i++)
                        {
                            Assert.AreEqual(1, sender.SendTo(10000, i % 2 == 0 ? "ch1" : "ch2", "Test"));
                        }

                        sender.StopAsyncSending(true, -1);
                        ch1.StopListening();
                        ch2.StopListening();
                    }
            Assert.AreEqual(500, ch1count);
            Assert.AreEqual(500, ch2count);
        }
예제 #2
0
        public void TestListenerDies()
        {
            using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel))
                using (IpcEventChannel sender = new IpcEventChannel(_registrar, _channel))
                {
                    ch1.StartListening("ch1");

                    ManualResetEvent ready = new ManualResetEvent(false);
                    ManualResetEvent die   = new ManualResetEvent(false);
                    ch1["Message"].OnEvent += delegate(object o, IpcSignalEventArgs e)
                    {
                        ready.Set();
                        die.WaitOne();
                        Thread.CurrentThread.Abort();
                    };

                    sender.Broadcast(100, "Message");
                    Assert.IsTrue(ready.WaitOne(1000, false));

                    sender.EnableAsyncSend();
                    sender.Broadcast(0, "Message");
                    die.Set();
                    sender.StopAsyncSending(true, 1000);
                    ch1.StopListening();
                }
        }
예제 #3
0
        public void TestBroadcastWithNonResponsive()
        {
            ManualResetEvent wait = new ManualResetEvent(false);
            int ch1count = 0, ch2count = 0;

            using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel))
                using (IpcEventChannel ch2 = new IpcEventChannel(_registrar, _channel))
                    using (IpcEventChannel sender = new IpcEventChannel(_registrar, _channel))
                    {
                        ch1.DefaultTimeout      = 100;
                        ch2.DefaultTimeout      = 100;
                        sender.ExecutionTimeout = 0;

                        ch1.StartListening("ch1");
                        ch2.StartListening("ch2");
                        sender.EnableAsyncSend();

                        ch1["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e)
                        { ch1count++; };
                        ch2["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e)
                        { ch2count++; wait.WaitOne(); };

                        sender.Broadcast(100, "Test");
                        sender.Broadcast(100, "Test");
                        sender.Broadcast(100, "Test");
                        sender.StopAsyncSending(false, 0);
                        ch1.StopListening();
                    }
            //We don't need to release the thread by wait.Set(), the thread was aborted by the
            //Dispose()... Had we called ch2.StopListening() instead, the program would hang.
            //thus to gracefully shutdown one calls StopListening()
            Assert.AreEqual(3, ch1count);
            Assert.AreEqual(1, ch2count);
        }