The code I use to setup the initial SqsMqServer is the same for the test as for my actual self hosted application. That works fine, I can post a message directly to a queue all day and watch the breakpoint fire… but when doing the exact same thing in a unit/integration test it never fires the registered callback.
I am trying to test the _sqsMqServer.RegisterHandler() but it never calls back in my test. I can see the queue appear and I can see the message is publishing in there… but it simply never fires off the callback in the RegisterHandler…
Any ideas are welcome… I’m stumped
[Test]
public void SQS_CanRegisterByTypeAndPublish_RecievesAndCountsMessage()
{
var custDemoWrapCalled = 0;
_sqsMqServer.RegisterHandler<CustomerDemographicsWrapper>(x =>
{
System.Diagnostics.Debugger.Break(); //should force the IDE to debug
Interlocked.Increment(ref custDemoWrapCalled); //stole this from ServiceStack
return x.GetBody();
});
var mqClient = _sqsMqServer.MessageFactory.CreateMessageQueueClient();
var message = new Message<CustomerDemographicsWrapper>(new CustomerDemographicsWrapper
{
CustomerDemographics = new CustomerDemographicsDto
{
Attn = "Test from Int. test",
Name = "Test name Int. test"
}
});
//Publish a message
mqClient.Publish(message);
var queueMgr = (_sqsMqServer.MessageFactory as ISqsMqMessageFactory).QueueManager;
var typeName = queueMgr.QueueNameMap.First().Key;
var queueName = queueMgr.QueueNameMap[typeName];
//IMessage<CustomerDemographicsWrapper> responseMsg = mqClient.Get<CustomerDemographicsWrapper>(queueName.QueueName);
//mqClient.Ack(responseMsg);
WaitUntilTrueOrTimeout(() => custDemoWrapCalled == 1, timeoutSeconds: 10);
Assert.That(_sqsMqServer.GetStats().TotalMessagesProcessed, Is.EqualTo(1));
Assert.That(custDemoWrapCalled, Is.EqualTo(1));
_sqsMqServer.Dispose();
Assert.True(true);
}
public static void WaitUntilTrueOrTimeout(Func<bool> doneWhenTrue, int timeoutSeconds = 10)
{
var timeoutAt = DateTime.UtcNow.AddSeconds(timeoutSeconds);
while (DateTime.UtcNow <= timeoutAt)
{
if (doneWhenTrue())
{
break;
}
Thread.Sleep(300);
}
}