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(); } }
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); }
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); }
public void TestChannelAbortPending() { AutoResetEvent finish = new AutoResetEvent(false); AutoResetEvent done = new AutoResetEvent(false); int count = 0; using (IpcEventChannel channel = new IpcEventChannel(_registrar, _channel)) { channel.EnableAsyncSend(); channel.StartListening(); channel["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e) { finish.WaitOne(); count++; done.Set(); }; Assert.AreEqual(1, channel.Broadcast(10000, "Test")); Assert.AreEqual(0, channel.Broadcast(0, "Test")); finish.Set(); done.WaitOne(); } Assert.AreEqual(1, count); }