Skip to content

Commit

Permalink
Format tests under ecflow/server
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosbento committed Sep 20, 2024
1 parent c6bc929 commit 95d42c8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
4 changes: 3 additions & 1 deletion libs/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ SET_TARGET_PROPERTIES(ecflow_server
# which point to directories outside the build tree to the install RPATH
#SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)


# ================================================================================
# TEST
ecbuild_add_test(
Expand All @@ -67,6 +67,7 @@ ecbuild_add_test(
Boost::boost # Boost header-only libraries must be available (namely unit_test_framework)
$<$<BOOL:${OPENSSL_FOUND}>:OpenSSL::SSL>
Threads::Threads
test_support
TEST_DEPENDS
u_base
)
Expand All @@ -90,6 +91,7 @@ ecbuild_add_test(
Boost::boost # Boost header-only libraries must be available (namely unit_test_framework)
$<$<BOOL:${OPENSSL_FOUND}>:OpenSSL::SSL>
Threads::Threads
test_support
TEST_DEPENDS
u_base
)
Expand Down
14 changes: 5 additions & 9 deletions libs/server/test/TestCheckPtSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@

#include <boost/test/unit_test.hpp>

#include "TestNaming.hpp"
#include "ecflow/server/CheckPtSaver.hpp"

// TODO: Move the following trace_*_function to a common test module/library
static void trace_test() {
std::cout << "..." << boost::unit_test::framework::current_test_case().full_name() << "\n";
}

/**
* A self cleaning test file, useful to automate test data storage/cleanup, with automatic generation of file names.
*/
Expand Down Expand Up @@ -72,7 +68,7 @@ BOOST_AUTO_TEST_SUITE(U_Server)
BOOST_AUTO_TEST_SUITE(T_CheckPtSaver)

BOOST_AUTO_TEST_CASE(test_checkpt_store_successful_case0) {
trace_test();
ECF_NAME_THIS_TEST();

// Case 0: neither current and backup exist

Expand All @@ -86,7 +82,7 @@ BOOST_AUTO_TEST_CASE(test_checkpt_store_successful_case0) {
}

BOOST_AUTO_TEST_CASE(test_checkpt_store_successful_case1) {
trace_test();
ECF_NAME_THIS_TEST();

// Case 1: current and backup both exist and are non-empty

Expand All @@ -100,7 +96,7 @@ BOOST_AUTO_TEST_CASE(test_checkpt_store_successful_case1) {
}

BOOST_AUTO_TEST_CASE(test_checkpt_store_successful_case2) {
trace_test();
ECF_NAME_THIS_TEST();

// Case 2: current and backup both exist, and current is empty

Expand All @@ -114,7 +110,7 @@ BOOST_AUTO_TEST_CASE(test_checkpt_store_successful_case2) {
}

BOOST_AUTO_TEST_CASE(test_checkpt_store_successful_case3) {
trace_test();
ECF_NAME_THIS_TEST();

// Case 3: current exists, but no backup is available

Expand Down
22 changes: 15 additions & 7 deletions libs/server/test/TestPeriodicScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <boost/test/unit_test.hpp>

#include "TestNaming.hpp"
#include "ecflow/server/PeriodicScheduler.hpp"

std::ostream& operator<<(std::ostream& os, const std::chrono::system_clock::time_point& tp) {
Expand Down Expand Up @@ -42,8 +43,8 @@ struct Collector
using instants_t = std::vector<instant_t>;

void operator()(instant_t now, instant_t last, instant_t next, bool is_boundary = true) {
std::cout << "Call at " << now << ", with is_boundary? " << (is_boundary ? "true" : "false") << ". Last call was at " << last
<< ". Next call at " << next << "." << std::endl;
std::cout << "Call at " << now << ", with is_boundary? " << (is_boundary ? "true" : "false")
<< ". Last call was at " << last << ". Next call at " << next << "." << std::endl;

// Activity must be called at minute boundary!
if (is_boundary && !instants.empty()) {
Expand All @@ -61,11 +62,12 @@ struct LongLasting
using instant_t = ecf::PeriodicScheduler<LongLasting>::instant_t;

template <typename DURATION>
explicit LongLasting(const DURATION& duration) : how_long_{std::chrono::duration_cast<std::chrono::milliseconds>(duration)} {}
explicit LongLasting(const DURATION& duration)
: how_long_{std::chrono::duration_cast<std::chrono::milliseconds>(duration)} {}

void operator()(instant_t now, instant_t last, instant_t next, bool is_boundary = true) {
std::cout << "Call at " << now << ", with is_boundary? " << (is_boundary ? "true" : "false") << ". Last call was at " << last
<< ". Next call at " << next << "." << std::endl;
std::cout << "Call at " << now << ", with is_boundary? " << (is_boundary ? "true" : "false")
<< ". Last call was at " << last << ". Next call at " << next << "." << std::endl;

std::this_thread::sleep_for(how_long_);
}
Expand All @@ -74,6 +76,8 @@ struct LongLasting
};

BOOST_AUTO_TEST_CASE(test_periodic_scheduler_over_one_minute) {
ECF_NAME_THIS_TEST();

// Setup time collector
Collector collector;
boost::asio::io_context io;
Expand All @@ -82,7 +86,8 @@ BOOST_AUTO_TEST_CASE(test_periodic_scheduler_over_one_minute) {

// Arrange time collector termination
ecf::Timer teardown(io);
teardown.set([&scheduler](const boost::system::error_code& error) { scheduler.terminate(); }, std::chrono::seconds(62));
teardown.set([&scheduler](const boost::system::error_code& error) { scheduler.terminate(); },
std::chrono::seconds(62));

// Run services
io.run();
Expand All @@ -91,6 +96,8 @@ BOOST_AUTO_TEST_CASE(test_periodic_scheduler_over_one_minute) {
}

BOOST_AUTO_TEST_CASE(test_periodic_scheduler_with_long_lasting_activity) {
ECF_NAME_THIS_TEST();

// Setup time collector
LongLasting activity{std::chrono::milliseconds(2499)};
boost::asio::io_context io;
Expand All @@ -99,7 +106,8 @@ BOOST_AUTO_TEST_CASE(test_periodic_scheduler_with_long_lasting_activity) {

// Arrange time collector termination
ecf::Timer teardown(io);
teardown.set([&scheduler](const boost::system::error_code& error) { scheduler.terminate(); }, std::chrono::seconds(60));
teardown.set([&scheduler](const boost::system::error_code& error) { scheduler.terminate(); },
std::chrono::seconds(60));

// Run services
io.run();
Expand Down
3 changes: 2 additions & 1 deletion libs/server/test/TestServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <boost/test/unit_test.hpp>

#include "TestNaming.hpp"
#include "ecflow/core/EcfPortLock.hpp"
#include "ecflow/core/Host.hpp"
#include "ecflow/core/Log.hpp"
Expand Down Expand Up @@ -149,7 +150,7 @@ void test_the_server(const std::string& port) {
}

BOOST_AUTO_TEST_CASE(test_server) {
cout << "Server:: ...test_server\n";
ECF_NAME_THIS_TEST();

// Create a unique port number, allowing debug and release,gnu,clang,intel to run at the same time
// Hence the lock file is not always sufficient.
Expand Down
17 changes: 11 additions & 6 deletions libs/server/test/TestServerEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <boost/test/unit_test.hpp>

#include "TestNaming.hpp"
#include "ecflow/core/CheckPt.hpp"
#include "ecflow/core/Converter.hpp"
#include "ecflow/core/Ecf.hpp"
Expand All @@ -32,7 +33,7 @@ BOOST_AUTO_TEST_SUITE(U_Server)
BOOST_AUTO_TEST_SUITE(T_ServerEnvironment)

BOOST_AUTO_TEST_CASE(test_server_environment_ecfinterval) {
cout << "Server:: ...test_server_environment_ecfinterval\n";
ECF_NAME_THIS_TEST();

// ecflow server interval is valid for range [1-60]
std::string port = Str::DEFAULT_PORT_NUMBER();
Expand Down Expand Up @@ -61,7 +62,7 @@ BOOST_AUTO_TEST_CASE(test_server_environment_ecfinterval) {
}

BOOST_AUTO_TEST_CASE(test_server_environment_port) {
cout << "Server:: ...test_server_environment_port\n";
ECF_NAME_THIS_TEST();

// The port numbers are divided into three ranges.\n";
// o the Well Known Ports, (require root permission) 0 -1023\n";
Expand Down Expand Up @@ -103,8 +104,9 @@ BOOST_AUTO_TEST_CASE(test_server_environment_port) {
}

BOOST_AUTO_TEST_CASE(test_server_environment_log_file) {
ECF_NAME_THIS_TEST();

// Regression test log file creation
cout << "Server:: ...test_server_environment_log_file\n";

int argc = 2;
char* argv[] = {const_cast<char*>("ServerEnvironment"), const_cast<char*>("--port=3144")};
Expand Down Expand Up @@ -138,8 +140,9 @@ BOOST_AUTO_TEST_CASE(test_server_environment_log_file) {
}

BOOST_AUTO_TEST_CASE(test_server_config_file) {
ECF_NAME_THIS_TEST();

// Regression test to make sure the server environment variable don't get removed
cout << "Server:: ...test_server_config_file\n";

int argc = 1;
char* argv[] = {const_cast<char*>("ServerEnvironment")};
Expand Down Expand Up @@ -280,8 +283,9 @@ BOOST_AUTO_TEST_CASE(test_server_config_file) {
}

BOOST_AUTO_TEST_CASE(test_server_environment_variables) {
ECF_NAME_THIS_TEST();

// Regression test to make sure the server environment variable don't get removed
cout << "Server:: ...test_server_environment_variables\n";

int argc = 2;
char* argv[] = {const_cast<char*>("ServerEnvironment"), const_cast<char*>("--port=3144")};
Expand Down Expand Up @@ -326,7 +330,8 @@ BOOST_AUTO_TEST_CASE(test_server_environment_variables) {
}

BOOST_AUTO_TEST_CASE(test_server_profile_threshold_environment_variable) {
cout << "Server:: ...test_server_profile_threshold_environment_variable\n";
ECF_NAME_THIS_TEST();

int argc = 1;
char* argv[] = {const_cast<char*>("ServerEnvironment")};
{
Expand Down

0 comments on commit 95d42c8

Please sign in to comment.