const size_t expected_responses = 1,
const std::string& server_response = "{ \"result\": 0 }") {
// Configure client side socket.
- configureControlSocket(server_type);
+ configureControlSocket(configured_service);
// Create server side socket.
- bindServerSocket(server_response);
+ bindServerSocket(server_response, true);
// The client side communication is synchronous. To be able to respond
- // to this we need to run the server side socket at the same time.
- // Running IO service in a thread guarantees that the server responds
- // as soon as it receives the control command.
- isc::util::thread::Thread th(boost::bind(&CtrlAgentCommandMgrTest::runIO,
- getIOService(), server_socket_,
- expected_responses));
+ // to this we need to run the server side socket at the same time as the
+ // client. Running IO service in a thread guarantees that the server
+ //responds as soon as it receives the control command.
+ isc::util::thread::Thread th(boost::bind(&IOService::run,
+ getIOService().get()));
+
+
+ // Wait for the IO service in thread to actually run.
+ server_socket_->waitForRunning();
ConstElementPtr command = createCommand("foo", service);
ConstElementPtr answer = mgr_.handleCommand("foo", ConstElementPtr(),
/// Check that error is returned to the client when the server to which the
/// command was forwarded sent an invalid message.
TEST_F(CtrlAgentCommandMgrTest, invalidAnswer) {
- testForward(CtrlAgentCfgContext::TYPE_DHCP6, "dhcp6",
+ testForward("dhcp6", "dhcp6",
+ isc::config::CONTROL_RESULT_ERROR, -1, -1, 1,
+ "{ \"result\": }");
+}
+
+/// Check that connection is dropped if it takes too long. The test checks
+/// client's behavior when partial JSON is returned. Client will be waiting
+/// for the '}' and will timeout because it is never received.
+/// @todo Currently this test is disabled because we don't have configurable
+/// timeout value. It is hardcoded to 5 sec, which is too long for the
+/// unit test to run.
+TEST_F(CtrlAgentCommandMgrTest, DISABLED_connectionTimeout) {
+ testForward(CtrlAgentCfgContext::TYPE_DHCP6, "dhcp6",
isc::config::CONTROL_RESULT_ERROR, -1, -1, 1,
"{ \"result\": 0");
}
// value is specified.
TEST_F(CtrlAgentCommandMgrTest, forwardListCommands) {
// Configure client side socket.
- configureControlSocket(CtrlAgentCfgContext::TYPE_DHCP4);
+ configureControlSocket("dhcp4");
// Create server side socket.
- bindServerSocket("{ \"result\" : 3 }");
+ bindServerSocket("{ \"result\" : 3 }", true);
// The client side communication is synchronous. To be able to respond
// to this we need to run the server side socket at the same time.