Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a default timeout when requesting a service from CLI. #486

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading