-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
How do I test callbacks/delegates which are not triggered
immediately? Especially when I need to do unit tests with an
event loop?
A simple example from my codebase (SaaSy here is a custom HTTP
client to an API endpoint):
class TestSaaSy {
mixin TestMixin;
// this works
void test_encoded_auth() {
auto ev = new EventLoop;
auto saasy = new SaaSy(ev, "test", "test");
assert(saasy.encoded_auth == "dGVzdDp0ZXN0dGVzdA==", "encoding issue");
ev.close;
ev.run;
}
// won't work. test gets finished even before the callback is fired!
void test_get_subscription() {
auto ev = new EventLoop;
auto saasy = new SaaSy(ev, "test", "test");
saasy.getSubscription("ref363466", (bool err, string response) {
assert(err == true);
ev.close;
});
ev.run;
}
}
Discussion in D forum: http://forum.dlang.org/thread/znwsshaqilmrfxswavjw@forum.dlang.org?page=2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels