Imagine a function like this:
private static ConcurrentList
For at least most simple-ish cases, I like to use an "expiring" assertion for this sort of thing. e.g.:
YourCollection sut = new YourCollection();
object newItem = new object();
sut.Add(newItem);
EventualAssert.IsTrue(() => sut.Contains(newItem), TimeSpan.FromSeconds(2));
where EventualAssert.IsTrue()
looks something like this:
public static void IsTrue(Func condition, TimeSpan timeout)
{
if (!SpinWait.SpinUntil(condition, timeout))
{
Assert.IsTrue(condition());
}
}
I also generally add an override with a default timeout which I use for most of my tests, but ymmv...