Skip to content

Commit

Permalink
Fix failing test for new ui jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasmeszaros committed Jan 18, 2022
1 parent d09a0ce commit 960158b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tests/slic3rutils/slic3r_jobs_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,28 @@ TEST_CASE("cancel_all should remove all pending jobs", "[Jobs]") {
auto pri = std::make_shared<Progress>();
BoostThreadWorker worker{pri};

std::array<bool, 4> jobres = {false};
std::array<bool, 4> 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);
Expand Down

0 comments on commit 960158b

Please sign in to comment.