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

[Test] Make tests independent with each other #9

Open
YingChen-Lee opened this issue Mar 28, 2023 · 2 comments
Open

[Test] Make tests independent with each other #9

YingChen-Lee opened this issue Mar 28, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@YingChen-Lee
Copy link
Collaborator

Drogon test framework is an asynchronous test framework. Therefore, if there are multiple tests, it's possible they run in the same time. In this case, different test cases would not be independent to each other.
We need to make the test being executed synchronously.

@YingChen-Lee YingChen-Lee added the bug Something isn't working label Mar 28, 2023
@HuaYuan-Tseng
Copy link
Contributor

Especially the operation of GameRepository.

DROGON_TEST(GIVEN_empty_WHEN_createGame_THEN_success)
{
    auto client = drogon::HttpClient::newHttpClient(HTTP_ADDRESS);
    std::string gameName1 = "Game1";
    drogon::HttpRequestPtr req1 = getRequestObj("gameName", gameName1, drogon::Post, "/CreateGame/createGame");
    client->sendRequest(req1, [TEST_CTX](drogon::ReqResult res, const drogon::HttpResponsePtr& resp) 
    {
        REQUIRE(res == drogon::ReqResult::Ok);
        REQUIRE(resp != nullptr);
        CHECK(resp->getStatusCode() == 200);
        LOG_INFO << resp->getBody();
    });
    GameRepository::self().ClearAllGames();
}

// TODO(issue #9): Fix the asynchronous problem so that different test cases won't interfere with each other.
DROGON_TEST(GIVEN_gameExists_WHEN_createGameWithSameName_THEN_reject)
{
    auto client = drogon::HttpClient::newHttpClient(HTTP_ADDRESS);
    std::string gameName2 = "Game2";
    drogon::HttpRequestPtr req1 = getRequestObj("gameName", gameName2, drogon::Post, "/CreateGame/createGame");
    client->sendRequest(req1, [TEST_CTX](drogon::ReqResult res, const drogon::HttpResponsePtr& resp) 
    {
        REQUIRE(res == drogon::ReqResult::Ok);
        REQUIRE(resp != nullptr);
    });

    drogon::HttpRequestPtr req2 = getRequestObj("gameName", gameName2, drogon::Post, "/CreateGame/createGame");
    client->sendRequest(req2, [TEST_CTX](drogon::ReqResult res, const drogon::HttpResponsePtr& resp)
    {
        REQUIRE(res == drogon::ReqResult::Ok);
        REQUIRE(resp != nullptr);
        CHECK(resp->getStatusCode() == 400);
        LOG_INFO << resp->getBody();
    });
    GameRepository::self().ClearAllGames();
}

@angtsusiong
Copy link
Contributor

I have a different opinion.

@angtsusiong angtsusiong reopened this Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants