Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing event loop based callbacks/delegates #5

Open
shripadk opened this issue Aug 31, 2012 · 0 comments
Open

Testing event loop based callbacks/delegates #5

shripadk opened this issue Aug 31, 2012 · 0 comments

Comments

@shripadk
Copy link

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/[email protected]?page=2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant