diff --git a/src/spider/client/Job.hpp b/src/spider/client/Job.hpp index ebbd2229c..f593a63ee 100644 --- a/src/spider/client/Job.hpp +++ b/src/spider/client/Job.hpp @@ -196,6 +196,7 @@ class Job { output_index = 0; } }); + return result; } else { if (output_task_ids.size() != 1) { throw ConnectionException{fmt::format("Expected one output task for job result")}; diff --git a/tests/client/client-test.cpp b/tests/client/client-test.cpp index b76b7a36b..77fbcb3c5 100644 --- a/tests/client/client-test.cpp +++ b/tests/client/client-test.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -88,6 +89,24 @@ auto main(int argc, char** argv) -> int { return cJobFailed; } + // Run task with multiple results should succeed + spider::Job> swap_job = driver.start(&swap_test, 1, 2); + spdlog::debug("Multiple result job started"); + swap_job.wait_complete(); + if (swap_job.get_status() != spider::JobStatus::Succeeded) { + spdlog::error("Multiple result job failed"); + return cJobFailed; + } + std::tuple swap_result = swap_job.get_result(); + if (std::get<0>(swap_result) != 2 || std::get<1>(swap_result) != 1) { + spdlog::error( + "Wrong multiple result job result. Get ({}, {}). Expect (2, 1)", + std::get<0>(swap_result), + std::get<1>(swap_result) + ); + return cJobFailed; + } + // Run fail job spider::Job fail_job = driver.start(&error_test, 1); spdlog::debug("Fail job started"); diff --git a/tests/worker/worker-test.cpp b/tests/worker/worker-test.cpp index 99340307f..ed5840fca 100644 --- a/tests/worker/worker-test.cpp +++ b/tests/worker/worker-test.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -15,6 +16,10 @@ auto sum_test(spider::TaskContext& /*context*/, int const x, int const y) -> int return x + y; } +auto swap_test(spider::TaskContext& /*context*/, int const x, int const y) -> std::tuple { + return std::make_tuple(y, x); +} + auto error_test(spider::TaskContext& /*context*/, int const /*x*/) -> int { throw std::runtime_error("Simulated error in worker"); } @@ -58,6 +63,7 @@ auto create_task_test(spider::TaskContext& context, int x, int y) -> int { // NOLINTBEGIN(cert-err58-cpp) SPIDER_REGISTER_TASK(sum_test); +SPIDER_REGISTER_TASK(swap_test); SPIDER_REGISTER_TASK(error_test); SPIDER_REGISTER_TASK(data_test); SPIDER_REGISTER_TASK(random_fail_test); diff --git a/tests/worker/worker-test.hpp b/tests/worker/worker-test.hpp index 1ae000285..691378642 100644 --- a/tests/worker/worker-test.hpp +++ b/tests/worker/worker-test.hpp @@ -1,11 +1,15 @@ #ifndef SPIDER_TEST_WORKER_TEST_HPP #define SPIDER_TEST_WORKER_TEST_HPP +#include + #include #include auto sum_test(spider::TaskContext& /*context*/, int x, int y) -> int; +auto swap_test(spider::TaskContext& /*context*/, int x, int y) -> std::tuple; + auto error_test(spider::TaskContext& /*context*/, int /*x*/) -> int; auto data_test(spider::TaskContext& /*context*/, spider::Data& data) -> int;