diff --git a/src/bin/agent/tests/ca_controller_unittests.cc b/src/bin/agent/tests/ca_controller_unittests.cc index 6fe750b848..dcda359c97 100644 --- a/src/bin/agent/tests/ca_controller_unittests.cc +++ b/src/bin/agent/tests/ca_controller_unittests.cc @@ -13,6 +13,7 @@ #include #include #include +#include using namespace std; using namespace isc::agent; @@ -676,8 +677,24 @@ TEST_F(CtrlAgentControllerTest, statusGet) { EXPECT_EQ(0, result->intValue()); ConstElementPtr arguments = response->get("arguments"); ASSERT_EQ(Element::map, arguments->getType()); - EXPECT_TRUE(arguments->contains("pid")); - EXPECT_TRUE(arguments->contains("uptime")); + + // The returned pid should be the pid of our process. + auto found_pid = arguments->get("pid"); + ASSERT_TRUE(found_pid); + EXPECT_EQ(static_cast(getpid()), found_pid->intValue()); + + // It is hard to check the actual uptime (and reload) as it is based + // on current time. Let's just make sure it is within a reasonable + // range. + auto found_uptime = arguments->get("uptime"); + ASSERT_TRUE(found_uptime); + EXPECT_LE(found_uptime->intValue(), 5); + EXPECT_GE(found_uptime->intValue(), 0); + + auto found_reload = arguments->get("reload"); + ASSERT_TRUE(found_reload); + EXPECT_LE(found_reload->intValue(), 5); + EXPECT_GE(found_reload->intValue(), 0); } } diff --git a/src/bin/d2/tests/d2_command_unittest.cc b/src/bin/d2/tests/d2_command_unittest.cc index 598a5e0807..c6690d75e2 100644 --- a/src/bin/d2/tests/d2_command_unittest.cc +++ b/src/bin/d2/tests/d2_command_unittest.cc @@ -23,6 +23,7 @@ #include #include #include +#include using namespace std; using namespace isc; @@ -632,9 +633,24 @@ TEST_F(CtrlChannelD2Test, statusGet) { EXPECT_EQ(0, result->intValue()); ConstElementPtr arguments = response->get("arguments"); ASSERT_EQ(Element::map, arguments->getType()); - EXPECT_TRUE(arguments->contains("pid")); - // launch is not called so we have only reload, not uptime. - EXPECT_TRUE(arguments->contains("reload")); + + // The returned pid should be the pid of our process. + auto found_pid = arguments->get("pid"); + ASSERT_TRUE(found_pid); + EXPECT_EQ(static_cast(getpid()), found_pid->intValue()); + + // It is hard to check the actual reload time as it is based + // on current time. Let's just make sure it is within a reasonable + // range. + auto found_reload = arguments->get("reload"); + ASSERT_TRUE(found_reload); + EXPECT_LE(found_reload->intValue(), 5); + EXPECT_GE(found_reload->intValue(), 0); + + /// @todo uptime is not available in this test, because the launch() + /// function is not called. This is not critical to test here, + /// because the same logic is tested for CA and in that case the + /// uptime is tested. } // Tests if the server returns its configuration using config-get. diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index 1dd4dea9a2..8930bc2aec 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -1049,8 +1049,24 @@ TEST_F(CtrlChannelDhcpv4SrvTest, statusGet) { EXPECT_EQ(0, result->intValue()); ConstElementPtr arguments = response->get("arguments"); ASSERT_EQ(Element::map, arguments->getType()); - EXPECT_TRUE(arguments->contains("pid")); - EXPECT_TRUE(arguments->contains("uptime")); + + // The returned pid should be the pid of our process. + auto found_pid = arguments->get("pid"); + ASSERT_TRUE(found_pid); + EXPECT_EQ(static_cast(getpid()), found_pid->intValue()); + + // It is hard to check the actual uptime (and reload) as it is based + // on current time. Let's just make sure it is within a reasonable + // range. + auto found_uptime = arguments->get("uptime"); + ASSERT_TRUE(found_uptime); + EXPECT_LE(found_uptime->intValue(), 5); + EXPECT_GE(found_uptime->intValue(), 0); + + auto found_reload = arguments->get("reload"); + ASSERT_TRUE(found_reload); + EXPECT_LE(found_reload->intValue(), 5); + EXPECT_GE(found_reload->intValue(), 0); } // This test verifies that the DHCP server handles config-backend-pull command diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index 106569f4dc..e81065716f 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -941,8 +942,24 @@ TEST_F(CtrlChannelDhcpv6SrvTest, statusGet) { EXPECT_EQ(0, result->intValue()); ConstElementPtr arguments = response->get("arguments"); ASSERT_EQ(Element::map, arguments->getType()); - EXPECT_TRUE(arguments->contains("pid")); - EXPECT_TRUE(arguments->contains("uptime")); + + // The returned pid should be the pid of our process. + auto found_pid = arguments->get("pid"); + ASSERT_TRUE(found_pid); + EXPECT_EQ(static_cast(getpid()), found_pid->intValue()); + + // It is hard to check the actual uptime (and reload) as it is based + // on current time. Let's just make sure it is within a reasonable + // range. + auto found_uptime = arguments->get("uptime"); + ASSERT_TRUE(found_uptime); + EXPECT_LE(found_uptime->intValue(), 5); + EXPECT_GE(found_uptime->intValue(), 0); + + auto found_reload = arguments->get("reload"); + ASSERT_TRUE(found_reload); + EXPECT_LE(found_reload->intValue(), 5); + EXPECT_GE(found_reload->intValue(), 0); } // This test verifies that the DHCP server handles server-tag-get command