Skip to content

Commit

Permalink
Use a default timeout when requesting a service from CLI.
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <caguero@openrobotics.org>
  • Loading branch information
caguero committed Mar 20, 2024
1 parent ab41ee3 commit 0f59b2f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/cmd/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,29 @@ TEST(gzTest, ServiceRequest)
ASSERT_EQ(output.cout, "data: " + value + "\n\n");
}

//////////////////////////////////////////////////
/// \brief Check 'gz service -r' to request a two-way service without timeout.
TEST(gzTest, ServiceRequestNoTimeout)
{
transport::Node node;

// Advertise a service.
std::string service = "/echo";
std::string value = "10";
EXPECT_TRUE(node.Advertise(service, srvEcho));

msgs::Int32 msg;
msg.set_data(10);

// Check the 'gz service -r' command.
auto output = custom_exec_str({"service",
"-s", service,
"--reqtype", "gz_msgs.Int32",
"--reptype", "gz_msgs.Int32",
"--req", "data: " + value});
ASSERT_EQ(output.cout, "data: " + value + "\n\n");
}

//////////////////////////////////////////////////
/// \brief Check 'gz service -r' to request a one-way service.
TEST(gzTest, ServiceOnewayRequest)
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/service_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct ServiceOptions
std::string repType{""};

/// \brief Timeout to use when requesting (in milliseconds)
int timeout{-1};
int timeout{1000};
};

//////////////////////////////////////////////////
Expand Down Expand Up @@ -104,7 +104,6 @@ void addServiceFlags(CLI::App &_app)
opt->repType, "Type of a response.");
auto timeoutOpt = _app.add_option("--timeout",
opt->timeout, "Timeout in milliseconds.");
repTypeOpt = repTypeOpt->needs(timeoutOpt);
timeoutOpt = timeoutOpt->needs(repTypeOpt);

auto command = _app.add_option_group("command", "Command to be executed.");
Expand Down

0 comments on commit 0f59b2f

Please sign in to comment.