Skip to content

Commit

Permalink
Merge pull request #378 from arogge/dev/arogge/master/fix-centos7-tests
Browse files Browse the repository at this point in the history
tests: make tests compile on rhel7
  • Loading branch information
arogge committed Dec 18, 2019
2 parents 1b4462e + 1e5c426 commit 8cd000b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
7 changes: 3 additions & 4 deletions core/src/tests/run_on_incoming_connect_interval.cc
Expand Up @@ -216,10 +216,9 @@ static void SimulateClientConnect(std::string client_name,

static void RunSchedulerAndSimulateClientConnect(BareosDb& db)
{
auto tts{std::make_unique<TestTimeSource>()};
auto ta{std::make_unique<TimeAdapter>(std::move(tts))};

Scheduler scheduler(std::move(ta), SchedulerJobCallback);
Scheduler scheduler(
std::make_unique<TimeAdapter>(std::make_unique<TestTimeSource>()),
SchedulerJobCallback);

std::thread scheduler_thread(scheduler_loop, &scheduler);

Expand Down
8 changes: 4 additions & 4 deletions core/src/tests/scheduler.cc
Expand Up @@ -159,7 +159,7 @@ void SimulatedTimeSource::ExecuteJob(JobControlRecord* jcr)

// auto tm = *std::gmtime(&t);
// std::cout << "Executing job: " << jcr->Job << std::endl;
// std::cout << std::put_time(&tm, "%d-%m-%Y %H:%M:%S") << std::endl;
// std::cout << put_time(&tm, "%d-%m-%Y %H:%M:%S") << std::endl;
}

static int CalculateAverage()
Expand Down Expand Up @@ -217,7 +217,7 @@ TEST_F(SchedulerTest, hourly)
for (const auto& t : list_of_job_execution_time_stamps) {
auto tm = *std::gmtime(&t);
std::cout << "Hour " << hour << ": "
<< std::put_time(&tm, "%d-%m-%Y %H:%M:%S");
<< put_time(&tm, "%d-%m-%Y %H:%M:%S");
if (hour) {
std::cout << " - " << list_of_time_gaps_between_adjacent_jobs[hour]
<< " sec";
Expand Down Expand Up @@ -267,7 +267,7 @@ TEST_F(SchedulerTest, on_time)
EXPECT_TRUE(is_two_o_clock);
EXPECT_TRUE(is_monday);
if (debug || !is_two_o_clock || !is_monday) {
std::cout << std::put_time(&tm, "%A, %d-%m-%Y %H:%M:%S ") << std::endl;
std::cout << put_time(&tm, "%A, %d-%m-%Y %H:%M:%S ") << std::endl;
}
}

Expand Down Expand Up @@ -295,7 +295,7 @@ TEST_F(SchedulerTest, add_job_with_no_run_resource_to_queue)
counter_of_number_of_jobs_run = 0;
maximum_number_of_jobs_run = 1;

auto scheduler_thread{std::thread([]() { scheduler->Run(); })};
std::thread scheduler_thread{[]() { scheduler->Run(); }};

JobResource* job{dynamic_cast<JobResource*>(
my_config->GetResWithName(R_JOB, "backup-bareos-fd"))};
Expand Down
11 changes: 10 additions & 1 deletion core/src/tests/scheduler_time_source.h
Expand Up @@ -28,10 +28,19 @@
#include <atomic>
#include <condition_variable>
#include <thread>
#include <iomanip>
#include <iostream>

static bool debug{false};

/* libstdc++ on rhel7 does not have put_time, so we add it here */
std::string put_time(const std::tm* tmb, const char* fmt) {
size_t maxlen = strlen(fmt)+100;
std::vector<char> s(maxlen);
strftime(s.data(), s.size(), fmt, tmb);
return std::string{s.data()};
}

class SimulatedTimeSource : public directordaemon::TimeSource {
public:
SimulatedTimeSource()
Expand All @@ -41,7 +50,7 @@ class SimulatedTimeSource : public directordaemon::TimeSource {

if (debug) {
time_t t{clock_value_};
std::cout << std::put_time(
std::cout << put_time(
gmtime(&t),
"Start simulated Clock at time: %d-%m-%Y %H:%M:%S")
<< std::endl;
Expand Down

0 comments on commit 8cd000b

Please sign in to comment.