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

Unstable unit test AsyncTasksTest.AsyncTasksNormal #8897

Closed
Lloyd-Pottiger opened this issue Apr 3, 2024 · 4 comments · Fixed by #8902
Closed

Unstable unit test AsyncTasksTest.AsyncTasksNormal #8897

Lloyd-Pottiger opened this issue Apr 3, 2024 · 4 comments · Fixed by #8902
Labels
component/storage severity/minor type/bug The issue is confirmed as a bug.

Comments

@Lloyd-Pottiger
Copy link
Contributor

Bug Report

https://ci.pingcap.net/blue/organizations/jenkins/tiflash-ghpr-unit-tests/detail/tiflash-ghpr-unit-tests/12996/pipeline

@JaySon-Huang
Copy link
Contributor

The test AsyncTasksTest.AsyncTasksNormal can not finished within 45 minutes, seems it hangs. @CalvinNeo

@CalvinNeo
Copy link
Member

Can't repeat by while ./dbms/gtests_dbms --gtest_filter="AsyncTasksTest.AsyncTasksNormal"; do :; done.
Maybe this is due to blocking between tests.

@CalvinNeo
Copy link
Member

3 -> 4 -> 1 -> block
3 -> 1 -> 4 -> 2 OK

    {
        auto async_tasks = std::make_unique<TestAsyncTasks>(1, 1, 2);
        auto m = std::make_shared<std::mutex>();
        auto m2 = std::make_shared<std::mutex>();
        int flag = 0;
        std::unique_lock cl(*m);
        async_tasks->addTask(1, [m, &flag, &async_tasks, m2, &log]() {
            auto cancel_handle = async_tasks->getCancelHandleFromExecutor(1);
            std::scoped_lock rl2(*m2); // 1
            std::scoped_lock rl(*m); // 2
            // Run after `cl` is released.
            if (cancel_handle->isCanceled())
            {
                return;
            }
            flag = 1;
        });
        async_tasks->asyncCancelTask(1);
        ASSERT_FALSE(async_tasks->isScheduled(1));
        async_tasks->addTask(1, [&flag]() { flag = 2; });
        cl.unlock(); // 3: Now can task 1 run.
        std::scoped_lock rl2(*m2); // 4: Wait until task1 finishes.
        ASSERT_NO_THROW(async_tasks->fetchResult(1));
        ASSERT_EQ(flag, 2);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/storage severity/minor type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants