Commit d8fdd817 authored by Marcin Siodelski's avatar Marcin Siodelski

[#1041] Extended statusGet unittests

The uptime, reload and pid returned are validated.
parent b3242fb7
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <process/testutils/d_test_stubs.h> #include <process/testutils/d_test_stubs.h>
#include <boost/pointer_cast.hpp> #include <boost/pointer_cast.hpp>
#include <sstream> #include <sstream>
#include <unistd.h>
using namespace std; using namespace std;
using namespace isc::agent; using namespace isc::agent;
...@@ -676,8 +677,24 @@ TEST_F(CtrlAgentControllerTest, statusGet) { ...@@ -676,8 +677,24 @@ TEST_F(CtrlAgentControllerTest, statusGet) {
EXPECT_EQ(0, result->intValue()); EXPECT_EQ(0, result->intValue());
ConstElementPtr arguments = response->get("arguments"); ConstElementPtr arguments = response->get("arguments");
ASSERT_EQ(Element::map, arguments->getType()); 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<int64_t>(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);
} }
} }
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <thread> #include <thread>
#include <unistd.h>
using namespace std; using namespace std;
using namespace isc; using namespace isc;
...@@ -632,9 +633,24 @@ TEST_F(CtrlChannelD2Test, statusGet) { ...@@ -632,9 +633,24 @@ TEST_F(CtrlChannelD2Test, statusGet) {
EXPECT_EQ(0, result->intValue()); EXPECT_EQ(0, result->intValue());
ConstElementPtr arguments = response->get("arguments"); ConstElementPtr arguments = response->get("arguments");
ASSERT_EQ(Element::map, arguments->getType()); ASSERT_EQ(Element::map, arguments->getType());
EXPECT_TRUE(arguments->contains("pid"));
// launch is not called so we have only reload, not uptime. // The returned pid should be the pid of our process.
EXPECT_TRUE(arguments->contains("reload")); auto found_pid = arguments->get("pid");
ASSERT_TRUE(found_pid);
EXPECT_EQ(static_cast<int64_t>(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. // Tests if the server returns its configuration using config-get.
......
...@@ -1049,8 +1049,24 @@ TEST_F(CtrlChannelDhcpv4SrvTest, statusGet) { ...@@ -1049,8 +1049,24 @@ TEST_F(CtrlChannelDhcpv4SrvTest, statusGet) {
EXPECT_EQ(0, result->intValue()); EXPECT_EQ(0, result->intValue());
ConstElementPtr arguments = response->get("arguments"); ConstElementPtr arguments = response->get("arguments");
ASSERT_EQ(Element::map, arguments->getType()); 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<int64_t>(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 // This test verifies that the DHCP server handles config-backend-pull command
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <cstdlib> #include <cstdlib>
#include <unistd.h>
#include <thread> #include <thread>
...@@ -941,8 +942,24 @@ TEST_F(CtrlChannelDhcpv6SrvTest, statusGet) { ...@@ -941,8 +942,24 @@ TEST_F(CtrlChannelDhcpv6SrvTest, statusGet) {
EXPECT_EQ(0, result->intValue()); EXPECT_EQ(0, result->intValue());
ConstElementPtr arguments = response->get("arguments"); ConstElementPtr arguments = response->get("arguments");
ASSERT_EQ(Element::map, arguments->getType()); 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<int64_t>(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 // This test verifies that the DHCP server handles server-tag-get command
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment