assertEventually

Checks a probe until the timeout expires. The assert error is produced if the probe fails to return 'true' before the timeout.

The parameter timeout determines the maximum timeout to wait before asserting a failure (default is 500ms).

The parameter delay determines how often the predicate will be checked (default is 10ms).

This kind of assertion is very useful to check on code that runs in another thread. For instance, the thread that listens to a socket.

static
void
assertEventually
(
bool delegate(
)
probe
,
Duration timeout = 500.msecs
,
Duration delay = 10.msecs
,
lazy string msg = null
,
string file = __FILE__
,
size_t line = __LINE__
)

Throws

AssertException when the probe fails to become true before timeout

Examples

1 assertEventually({ static count = 0; return ++count > 23; });
2 
3 auto exception = expectThrows!AssertException(assertEventually({ return false; }));
4 
5 assertEquals("timed out", exception.msg);

Meta