Created
March 26, 2012 19:36
-
-
Save jasonyandell/2209041 to your computer and use it in GitHub Desktop.
Round Robin test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void RoundRobinWorks() | |
{ | |
var busA = ServiceLocator.Current.GetInstance<ITransientBus>(); | |
var busB = ServiceLocator.Current.GetInstance<ITransientBus>(); | |
Assert.AreNotEqual(busA, busB); | |
var evtA = new ManualResetEvent(false); | |
var evtB = new ManualResetEvent(false); | |
busA.SubscribeWithAction<IStringMessage>(x => | |
evtA.Set()); | |
busB.SubscribeWithAction<IStringMessage>(x => | |
evtB.Set()); | |
// Empty current queue, if anything is even there | |
evtA.WaitOne(TimeSpan.FromSeconds(0.5)); | |
evtB.WaitOne(TimeSpan.FromMilliseconds(1)); | |
// reset the events so they're un-flagged | |
// (in case the queue was not empty when this test was run) | |
evtA.Reset(); | |
evtB.Reset(); | |
MessageBus.Instance.Publish((new StringMessage { Value = "end-to-end test0" }) as IStringMessage); | |
MessageBus.Instance.Publish((new StringMessage { Value = "end-to-end test1" }) as IStringMessage); | |
Assert.IsTrue(evtA.WaitOne(500), "Timed out waiting for message A"); | |
Assert.IsTrue(evtB.WaitOne(500), "Timed out waiting for message B"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment