Skip to content

gz_TEST: improve initial sim time test reliability #1916

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

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Changes from 1 commit
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
21 changes: 18 additions & 3 deletions src/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ TEST(CmdLine, GazeboServer)
TEST(CmdLine, SimtimeArgument)
{
std::string cmd =
kGzCommand + " -r -v 4 --iterations 100 --initial-sim-time 1000.5 " +
kGzCommand + " -r -v 4 --iterations 500 --initial-sim-time 1000.5 " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the loaded sdf file has some plugins, none of the more time consuming plugins such as Physics are loaded. Also, the plugins.sdf world is set to run as fast as possible, so this command may finish running before transport is done initializing. My suggestion is to slow it down using -z 1000 or even -z 100.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string(PROJECT_SOURCE_PATH) + "/test/worlds/plugins.sdf";

std::cout << "Running command [" << cmd << "]" << std::endl;
Expand All @@ -144,7 +144,7 @@ TEST(CmdLine, SimtimeArgument)
gz::transport::Node node;
auto cb = [&](const gz::msgs::Clock &_msg) -> void
{
EXPECT_GE(_msg.sim().sec() + _msg.sim().nsec()/1000000000.0,
EXPECT_GE(_msg.sim().sec() + 1e-9 * _msg.sim().nsec(),
1000.5);
msgCount++;
};
Expand All @@ -153,7 +153,22 @@ TEST(CmdLine, SimtimeArgument)
EXPECT_TRUE(node.Subscribe(std::string("/clock"), cbFcn));

std::string output = customExecStr(cmd);
EXPECT_GT(msgCount, 0);

// Try waiting different amounts if no messages have been received
if (!msgCount)
{
for (auto i : {1, 10, 100, 1000})
{
std::cout << "Sleeping for " << i << " ms";
GZ_SLEEP_MS(i);
std::cout << ", recevied " << msgCount << " messages." << std::endl;
if (msgCount)
{
break;
}
}
}
EXPECT_GT(msgCount, 0) << output;
}

/////////////////////////////////////////////////
Expand Down