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

Feature Request: Would like a built-in way to prevent expiring async mocks #303

Open
Mskeffington opened this issue May 12, 2023 · 0 comments

Comments

@Mskeffington
Copy link

considering the following code:

SECTION("test async function") {
        std::condition_variable cv;
        std::mutex cvMutex;

        REQUIRE_CALL(myMock, call_async())
            .LR_SIDE_EFFECT(cv.notify_all());

        // wrapper contains an instance of the mock which is called on the other side of an RPC
        wrapper.call_async();

        // In order to prevent timing out the REQUIRE_CALL, I need to wait for the call to end before the block exits. 
        std::unique_lock<std::mutex> lock(cvMutex);
        // specify a timeout of 1s.  This normally takes less than 1s during a successful test
        REQUIRE(cv.wait_for(lock, 1s) == std::cv_status::no_timeout);
}

I would love a way to wrap this very verbose functionality. Maybe like this:

SECTION("test async function") {
        REQUIRE_CALL(myMock, call_async())
            .ASYNC_TIMEOUT(1s);

        wrapper.call_async();
        // could also wrap the call in a macro if neccecary...
}
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