Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/spider/client/Job.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class Job {
output_index = 0;
}
});
return result;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

LGTM! Critical fix for tuple result handling.

Added the missing return statement for tuple specialization case, which is essential for the multiple results functionality to work correctly.

} else {
if (output_task_ids.size() != 1) {
throw ConnectionException{fmt::format("Expected one output task for job result")};
Expand Down
19 changes: 19 additions & 0 deletions tests/client/client-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <string>
#include <tuple>

#include <boost/any/bad_any_cast.hpp>
#include <boost/program_options/errors.hpp>
Expand Down Expand Up @@ -88,6 +89,24 @@ auto main(int argc, char** argv) -> int {
return cJobFailed;
}

// Run task with multiple results should succeed
spider::Job<std::tuple<int, int>> 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<int, int> 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");
Expand Down
6 changes: 6 additions & 0 deletions tests/worker/worker-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <iostream>
#include <random>
#include <stdexcept>
#include <tuple>

#include <spider/client/Data.hpp>
#include <spider/client/Driver.hpp>
Expand All @@ -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<int, int> {
return std::make_tuple(y, x);
}

auto error_test(spider::TaskContext& /*context*/, int const /*x*/) -> int {
throw std::runtime_error("Simulated error in worker");
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions tests/worker/worker-test.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#ifndef SPIDER_TEST_WORKER_TEST_HPP
#define SPIDER_TEST_WORKER_TEST_HPP

#include <tuple>

#include <spider/client/Data.hpp>
#include <spider/client/TaskContext.hpp>

auto sum_test(spider::TaskContext& /*context*/, int x, int y) -> int;

auto swap_test(spider::TaskContext& /*context*/, int x, int y) -> std::tuple<int, int>;

auto error_test(spider::TaskContext& /*context*/, int /*x*/) -> int;

auto data_test(spider::TaskContext& /*context*/, spider::Data<int>& data) -> int;
Expand Down