From 960158b79f5e548eeff623dd5c114238344bc390 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 18 Jan 2022 10:54:37 +0100 Subject: [PATCH] Fix failing test for new ui jobs --- tests/slic3rutils/slic3r_jobs_tests.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/slic3rutils/slic3r_jobs_tests.cpp b/tests/slic3rutils/slic3r_jobs_tests.cpp index 39682ff98..d31b07349 100644 --- a/tests/slic3rutils/slic3r_jobs_tests.cpp +++ b/tests/slic3rutils/slic3r_jobs_tests.cpp @@ -95,26 +95,28 @@ TEST_CASE("cancel_all should remove all pending jobs", "[Jobs]") { auto pri = std::make_shared(); BoostThreadWorker worker{pri}; - std::array jobres = {false}; + std::array jobres = {false, false, false, false}; queue_job(worker, [&jobres](Job::Ctl &) { jobres[0] = true; - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // FIXME: the long wait time is needed to prevent fail in MSVC + // where the sleep_for function is behaving stupidly. + // see https://developercommunity.visualstudio.com/t/bogus-stdthis-threadsleep-for-implementation/58530 + std::this_thread::sleep_for(std::chrono::seconds(1)); }); queue_job(worker, [&jobres](Job::Ctl &) { jobres[1] = true; - std::this_thread::sleep_for(std::chrono::milliseconds(1)); }); queue_job(worker, [&jobres](Job::Ctl &) { jobres[2] = true; - std::this_thread::sleep_for(std::chrono::milliseconds(1)); }); queue_job(worker, [&jobres](Job::Ctl &) { jobres[3] = true; - std::this_thread::sleep_for(std::chrono::milliseconds(1)); }); - std::this_thread::sleep_for(std::chrono::microseconds(500)); + // wait until the first job's half time to be sure, the cancel is made + // during the first job's execution. + std::this_thread::sleep_for(std::chrono::milliseconds(500)); worker.cancel_all(); REQUIRE(jobres[0] == true);