Skip to content

Commit

Permalink
Fix clang tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
sitaowang1998 committed Jan 3, 2025
1 parent 2a9c6f7 commit 93cb2b6
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/spider/client/Driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <stdexcept>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>

#include <boost/uuid/random_generator.hpp>
Expand Down
17 changes: 15 additions & 2 deletions src/spider/client/Job.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@
#define SPIDER_CLIENT_JOB_HPP

#include <chrono>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <thread>
#include <tuple>
#include <utility>
#include <vector>

#include <boost/uuid/uuid.hpp>
#include <fmt/format.h>

#include "../core/DataImpl.hpp"
#include "../core/Error.hpp"
#include "../core/JobMetadata.hpp"
#include "../io/MsgPack.hpp" // IWYU pragma: keep
#include "../storage/MetadataStorage.hpp"
#include "Data.hpp"
#include "task.hpp"
#include "type_utils.hpp"

Expand All @@ -22,6 +29,8 @@ namespace core {
class Data;
class DataStorage;
class MetadataStorage;
class Task;
class TaskOutput;
} // namespace core
class Driver;

Expand Down Expand Up @@ -58,7 +67,8 @@ class Job {
};
}
while (!complete) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
constexpr int cSleepMs = 10;
std::this_thread::sleep_for(std::chrono::milliseconds(cSleepMs));
err = m_metadata_storage->get_job_complete(m_id, &complete);
if (!err.success()) {
throw ConnectionException{
Expand All @@ -80,7 +90,7 @@ class Job {
* @throw spider::ConnectionException
*/
auto get_status() -> JobStatus {
core::JobStatus status;
core::JobStatus status = core::JobStatus::Running;
core::StorageErr const err = m_metadata_storage->get_job_status(m_id, &status);
if (!err.success()) {
throw ConnectionException{fmt::format("Failed to get job status: {}", err.description)};
Expand All @@ -100,6 +110,7 @@ class Job {
};
}

// NOLINTBEGIN(readability-function-cognitive-complexity)
/**
* NOTE: It is undefined behavior to call this method for a job that is not in the `Succeeded`
* state.
Expand Down Expand Up @@ -231,6 +242,8 @@ class Job {
}
}

// NOLINTEND(readability-function-cognitive-complexity)

/**
* NOTE: It is undefined behavior to call this method for a job that is not in the `Failed`
* state.
Expand Down
13 changes: 8 additions & 5 deletions src/spider/client/type_utils.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#ifndef SPIDER_CLIENT_TYPE_UTILS_HPP
#define SPIDER_CLIENT_TYPE_UTILS_HPP

#include <cstddef>
#include <initializer_list>
#include <type_traits>
#include <utility>

namespace spider {
// The template and partial specialization below check whether a given type is a specialization of
Expand Down Expand Up @@ -45,16 +48,16 @@ void for_n(F func) {

template <class T>
struct ExtractTemplateParam {
using type = T;
using Type = T;
};

template <template <class> class T, class P>
struct ExtractTemplateParam<T<P>> {
using type = P;
template <template <class> class t, class P>
struct ExtractTemplateParam<t<P>> {
using Type = P;
};

template <class T>
using ExtractTemplateParamT = typename ExtractTemplateParam<T>::type;
using ExtractTemplateParamT = typename ExtractTemplateParam<T>::Type;

} // namespace spider
#endif // SPIDER_CLIENT_TYPE_UTILS_HPP
4 changes: 4 additions & 0 deletions src/spider/storage/MysqlStorage.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MysqlStorage.hpp"

#include <algorithm>
#include <array>
#include <chrono>
#include <cstdint>
Expand Down Expand Up @@ -490,6 +491,7 @@ void MySqlMetadataStorage::add_task(sql::bytes job_id, Task const& task) {
}
}

// NOLINTBEGIN(readability-function-cognitive-complexity)
auto MySqlMetadataStorage::add_job(
boost::uuids::uuid job_id,
boost::uuids::uuid client_id,
Expand Down Expand Up @@ -623,6 +625,8 @@ auto MySqlMetadataStorage::add_job(
return StorageErr{};
}

// NOLINTEND(readability-function-cognitive-complexity)

namespace {

auto fetch_task(std::unique_ptr<sql::ResultSet> const& res) -> Task {
Expand Down
1 change: 0 additions & 1 deletion src/spider/worker/FunctionManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <cstdint>
#include <exception>
#include <functional>
#include <initializer_list>
#include <memory>
#include <optional>
#include <string>
Expand Down
18 changes: 13 additions & 5 deletions tests/client/client-test.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <string>

#include <boost/any/bad_any_cast.hpp>
#include <boost/program_options/errors.hpp>
#include <boost/program_options/options_description.hpp>
Expand All @@ -7,6 +9,10 @@
#include <spdlog/sinks/stdout_color_sinks.h> // IWYU pragma: keep
#include <spdlog/spdlog.h>

#include "../../src/spider/client/Data.hpp"
#include "../../src/spider/client/Driver.hpp"
#include "../../src/spider/client/Job.hpp"
#include "../../src/spider/client/TaskGraph.hpp"
#include "../worker/worker-test.hpp"

namespace {
Expand Down Expand Up @@ -34,6 +40,7 @@ constexpr int cJobFailed = 2;

} // namespace

// NOLINTNEXTLINE(bugprone-exception-escape)
auto main(int argc, char** argv) -> int {
// NOLINTNEXTLINE(misc-include-cleaner)
spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] [spider.scheduler] %v");
Expand Down Expand Up @@ -61,8 +68,8 @@ auto main(int argc, char** argv) -> int {
spdlog::debug("Driver created");

// Run a complicated graph that should succeed
spider::TaskGraph left = driver.bind(&sum_test, &data_test, &data_test);
spider::TaskGraph graph = driver.bind(&sum_test, left, &sum_test);
spider::TaskGraph const left = driver.bind(&sum_test, &data_test, &data_test);
spider::TaskGraph const graph = driver.bind(&sum_test, left, &sum_test);
spdlog::debug("Graph created");
spider::Data<int> d1 = driver.get_data_builder<int>().build(1);
spider::Data<int> d2 = driver.get_data_builder<int>().build(2);
Expand All @@ -75,7 +82,8 @@ auto main(int argc, char** argv) -> int {
spdlog::error("Job failed");
return cJobFailed;
}
if (job.get_result() != 10) {
constexpr int cExpectedResult = 10;
if (job.get_result() != cExpectedResult) {
spdlog::error("Wrong job result. Get {}. Expect 10", job.get_result());
return cJobFailed;
}
Expand All @@ -91,8 +99,8 @@ auto main(int argc, char** argv) -> int {
}

// Run random fail job
constexpr int fail_rate = 5;
spider::Job random_fail_job = driver.start(&random_fail_test, fail_rate);
constexpr int cFailRate = 5;
spider::Job random_fail_job = driver.start(&random_fail_test, cFailRate);
spdlog::debug("Random fail job started");
random_fail_job.wait_complete();
spdlog::debug("Random fail job completed");
Expand Down
1 change: 1 addition & 0 deletions tests/worker/worker-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <random>
#include <stdexcept>

#include "../../src/spider/client/Data.hpp"
#include "../../src/spider/client/Driver.hpp"
#include "../../src/spider/client/TaskContext.hpp"

Expand Down
6 changes: 3 additions & 3 deletions tests/worker/worker-test.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef SPIDER_TEST_WORKER_TEST_HPP
#define SPIDER_TEST_WORKER_TEST_HPP

#include "../../src/spider/client/Driver.hpp"
#include "../../src/spider/client/Data.hpp"
#include "../../src/spider/client/TaskContext.hpp"

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

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

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

Expand Down

0 comments on commit 93cb2b6

Please sign in to comment.