diff --git a/src/test_api.cpp b/src/test_api.cpp index 08163d0..ef3697d 100644 --- a/src/test_api.cpp +++ b/src/test_api.cpp @@ -28,6 +28,7 @@ class TestThread { ~TestThread() { join(); } void routine() { + LOG(INFO) << "Started routine"; size_t distance{0}; std::unique_lock lock(mtx); const std::stop_token stoken = thr.get_stop_token(); diff --git a/tests/test_base64.cpp b/tests/test_base64.cpp index a4190ff..23aacb2 100644 --- a/tests/test_base64.cpp +++ b/tests/test_base64.cpp @@ -13,7 +13,9 @@ class Base64Test : public ::testing::Test { protected: void SetUp() override { - + FLAGS_logtostderr = true; + if (!google::IsGoogleLoggingInitialized()) + google::InitGoogleLogging("TestCli"); } void TearDown() override { diff --git a/tests/test_base64_edge_cases.cpp b/tests/test_base64_edge_cases.cpp index a50ae40..ffaf7be 100644 --- a/tests/test_base64_edge_cases.cpp +++ b/tests/test_base64_edge_cases.cpp @@ -1,11 +1,17 @@ #include "cloud_point_rpc/rpc_coder.hpp" #include #include +#include using namespace score; class Base64EdgeCaseTest : public ::testing::Test { protected: + void SetUp() override { + FLAGS_logtostderr = true; + if (!google::IsGoogleLoggingInitialized()) + google::InitGoogleLogging("TestRPC"); + } Base64RPCCoder coder; }; diff --git a/tests/test_c_api.cpp b/tests/test_c_api.cpp index 1b97d98..5fdd20a 100644 --- a/tests/test_c_api.cpp +++ b/tests/test_c_api.cpp @@ -5,6 +5,7 @@ #include #include #include +#include class TestCApi : public ::testing::Test { protected: @@ -19,7 +20,6 @@ class TestCApi : public ::testing::Test { }; TEST_F(TestCApi, Base) { - rpc_string name; name.s = "test"; static std::promise task; @@ -163,6 +163,30 @@ TEST_F(TestCApi, ScheduleCall) { test_idx.template operator()<3>(); } +TEST(TestTestCApi, InitDeinitOnLongRunningTask) { + using namespace std::chrono_literals; + FLAGS_logtostderr = true; + if (!google::IsGoogleLoggingInitialized()) + google::InitGoogleLogging("TestRPC"); + EXPECT_NO_THROW(crpc_test_init()); + static std::promise bridge; + std::string_view name = "long running task"; + crpc_test_add_method( + +[](rpc_string *) -> rpc_string * { + static bool installed = false; + if (!installed) { + installed = true; + bridge.set_value(true); + } + std::string_view res = "res"; + std::this_thread::sleep_for(3s); + return crpc_str_create(res.data(), res.size()); + }, + crpc_str_create(name.data(), name.size())); + std::this_thread::sleep_for(500ms); + crpc_test_deinit(); +} + TEST_F(TestCApi, String) { rpc_string name; name.s = "test"; diff --git a/tests/test_cli.cpp b/tests/test_cli.cpp index a94fdc4..2ede988 100644 --- a/tests/test_cli.cpp +++ b/tests/test_cli.cpp @@ -19,6 +19,9 @@ public: protected: void SetUp() override { + FLAGS_logtostderr = true; + if (!google::IsGoogleLoggingInitialized()) + google::InitGoogleLogging("TestCli"); server_ip = "127.0.0.1"; server_port = 9096; diff --git a/tests/test_integration.cpp b/tests/test_integration.cpp index 1acef21..0fd3245 100644 --- a/tests/test_integration.cpp +++ b/tests/test_integration.cpp @@ -16,6 +16,9 @@ using namespace score; class IntegrationTest : public ::testing::Test { protected: void SetUp() override { + FLAGS_logtostderr = true; + if (!google::IsGoogleLoggingInitialized()) + google::InitGoogleLogging("TestCli"); // Create a temporary config file for testing std::ofstream config_file("config.yaml"); config_file diff --git a/tests/test_rpc.cpp b/tests/test_rpc.cpp index 3d2798e..93e77d5 100644 --- a/tests/test_rpc.cpp +++ b/tests/test_rpc.cpp @@ -15,6 +15,9 @@ class RpcServerTest : public ::testing::Test { Service service; void SetUp() override { + FLAGS_logtostderr = true; + if (!google::IsGoogleLoggingInitialized()) + google::InitGoogleLogging("TestCli"); server.register_method("get-intrinsic-params", [&](const json &) { return service.get_intrinsic_params(); }); diff --git a/tests/test_rpc_edge_cases.cpp b/tests/test_rpc_edge_cases.cpp index 277a2f4..fc0507c 100644 --- a/tests/test_rpc_edge_cases.cpp +++ b/tests/test_rpc_edge_cases.cpp @@ -2,6 +2,7 @@ #include "server_api.h" #include #include +#include #include #include #include @@ -15,6 +16,9 @@ class RpcServerEdgeCaseTest : public ::testing::Test { RpcServer server; void SetUp() override { + FLAGS_logtostderr = true; + if (!google::IsGoogleLoggingInitialized()) + google::InitGoogleLogging("TestCli"); server.register_method( "echo", [&](const json &j) { return j.get(); }); server.register_method("thrower", [&](const json &) -> std::string { diff --git a/tests/test_serialize.cpp b/tests/test_serialize.cpp index 371674b..145becd 100644 --- a/tests/test_serialize.cpp +++ b/tests/test_serialize.cpp @@ -1,11 +1,19 @@ #include "cloud_point_rpc/serialize.hpp" #include #include +#include #include using namespace score; -class SerializeEdgeCaseTest : public ::testing::Test {}; +class SerializeEdgeCaseTest : public ::testing::Test { + protected: + void SetUp() override { + FLAGS_logtostderr = true; + if (!google::IsGoogleLoggingInitialized()) + google::InitGoogleLogging("TestRPC"); + } +}; // uint8_t round-trip TEST_F(SerializeEdgeCaseTest, Uint8RoundTrip) { diff --git a/tests/test_service.cpp b/tests/test_service.cpp index 929bcc8..49d2306 100644 --- a/tests/test_service.cpp +++ b/tests/test_service.cpp @@ -4,7 +4,14 @@ using namespace score; -class ServiceEdgeCaseTest : public ::testing::Test {}; +class ServiceEdgeCaseTest : public ::testing::Test { + protected: + void SetUp() override { + FLAGS_logtostderr = true; + if (!google::IsGoogleLoggingInitialized()) + google::InitGoogleLogging("TestRPC"); + } +}; // Default constructor (no data) TEST_F(ServiceEdgeCaseTest, DefaultConstructorFallbacks) { diff --git a/tests/test_tcp.cpp b/tests/test_tcp.cpp index 4046853..3fe126a 100644 --- a/tests/test_tcp.cpp +++ b/tests/test_tcp.cpp @@ -15,6 +15,9 @@ class TcpTest : public ::testing::Test { protected: void SetUp() override { + FLAGS_logtostderr = true; + if (!google::IsGoogleLoggingInitialized()) + google::InitGoogleLogging("TestRPC"); server_ = std::make_unique( "127.0.0.1", 12345, [this](const std::string &request) { EXPECT_EQ(request, expected_); @@ -55,4 +58,4 @@ TEST_F(TcpTest, HugeBuffer) { ExpectedResponse(data); score::TCPConnector connector("127.0.0.1", 12345); auto res = connector.Send(data); -} \ No newline at end of file +} diff --git a/tests/test_tcp_edge_cases.cpp b/tests/test_tcp_edge_cases.cpp index d2c6f04..28aa4e5 100644 --- a/tests/test_tcp_edge_cases.cpp +++ b/tests/test_tcp_edge_cases.cpp @@ -28,6 +28,12 @@ class TcpEdgeCaseTest : public ::testing::Test { } } + void SetUp() override { + FLAGS_logtostderr = true; + if (!google::IsGoogleLoggingInitialized()) + google::InitGoogleLogging("TestRPC"); + } + void TearDown() override { StopServer(); } };