Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authortamasmeszaros <meszaros.q@gmail.com>2021-12-02 17:34:20 +0300
committertamasmeszaros <meszaros.q@gmail.com>2022-01-11 13:26:26 +0300
commite367ef8011ffa419ab1decb035e5fb46f01c8ae1 (patch)
tree039f15c9416f59f595bcbf6c419f9dc5028c170f /tests
parent583c123c9703d95a4ae944c981554e7fda3a57d0 (diff)
Fix job tests on Win, don't use usleep()
Diffstat (limited to 'tests')
-rw-r--r--tests/slic3rutils/slic3r_jobs_tests.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/tests/slic3rutils/slic3r_jobs_tests.cpp b/tests/slic3rutils/slic3r_jobs_tests.cpp
index 9c75d79ac..56c2fab43 100644
--- a/tests/slic3rutils/slic3r_jobs_tests.cpp
+++ b/tests/slic3rutils/slic3r_jobs_tests.cpp
@@ -1,8 +1,13 @@
#include "catch2/catch.hpp"
+#include <chrono>
+#include <thread>
+
#include "slic3r/GUI/Jobs/BoostThreadWorker.hpp"
#include "slic3r/GUI/Jobs/ProgressIndicator.hpp"
+//#include <boost/thread/thread.hpp>
+
struct Progress: Slic3r::ProgressIndicator {
int range = 100;
int pr = 0;
@@ -68,7 +73,7 @@ TEST_CASE("Cancellation should be recognized be the worker", "[Jobs]") {
worker,
[](Job::Ctl &ctl) {
for (int s = 0; s <= 100; ++s) {
- usleep(10000);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
ctl.update_status(s, "Running");
if (ctl.was_canceled()) break;
}
@@ -77,7 +82,7 @@ TEST_CASE("Cancellation should be recognized be the worker", "[Jobs]") {
REQUIRE(cancelled == true);
});
- usleep(1000);
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
worker.cancel();
while (!worker.is_idle())
@@ -95,12 +100,24 @@ TEST_CASE("cancel_all should remove all pending jobs", "[Jobs]") {
std::array<bool, 4> jobres = {false};
- queue_job(worker, [&jobres](Job::Ctl &) { jobres[0] = true; usleep(1000); });
- queue_job(worker, [&jobres](Job::Ctl &) { jobres[1] = true; usleep(1000); });
- queue_job(worker, [&jobres](Job::Ctl &) { jobres[2] = true; usleep(1000); });
- queue_job(worker, [&jobres](Job::Ctl &) { jobres[3] = true; usleep(1000); });
+ queue_job(worker, [&jobres](Job::Ctl &) {
+ jobres[0] = true;
+ std::this_thread::sleep_for(std::chrono::milliseconds(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));
+ });
- usleep(500);
+ std::this_thread::sleep_for(std::chrono::microseconds(500));
worker.cancel_all();
REQUIRE(jobres[0] == true);