Wednesday, December 2, 2009

EnqueueConditional never passing

I came across a unit test that seemed to hang. Problem was with the EnqueConditional() method which essentially never became true. A quick search turned up this blog post which has a solution.

Making sure asynchronous donesn't cause a deadlock

EnqueueConditional(() =>
{
// SP: Added timeout on checking the IsBusy
Assert.IsTrue((DateTime.Now - startTime) < TimeSpan.FromSeconds(30), "Timeout on condition 'StudImpVM.IsBusy == false;'");
return StudImpVM.IsBusy == false;
});

Adding this Assert into the conditional check causes it to fail the unit test rather than sit waiting for something that may never happen.

0 comments: