Skip to content

Instantly share code, notes, and snippets.

@jasonyandell
Created March 26, 2012 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonyandell/2209041 to your computer and use it in GitHub Desktop.
Save jasonyandell/2209041 to your computer and use it in GitHub Desktop.
Round Robin test
[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