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

Expose the ability to stop a server #1551

Merged
merged 4 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions include/ignition/gazebo/Server.hh
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ namespace ignition
bool _recursive = true,
const unsigned int _worldIndex = 0);

/// \brief Stop the server. This will stop all running simulations.
public: void Stop();

/// \brief Private data
private: std::unique_ptr<ServerPrivate> dataPtr;
};
Expand Down
6 changes: 6 additions & 0 deletions src/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,9 @@ bool Server::RequestRemoveEntity(const Entity _entity,

return false;
}

//////////////////////////////////////////////////
void Server::Stop()
{
this->dataPtr->Stop();
}
56 changes: 40 additions & 16 deletions src/Server_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ TEST_P(ServerFixture, IGN_UTILS_TEST_DISABLED_ON_WIN32(ServerConfigRealPlugin))
// Start server
ServerConfig serverConfig;
serverConfig.SetUpdateRate(10000);
serverConfig.SetSdfFile(std::string(PROJECT_SOURCE_PATH) +
"/test/worlds/shapes.sdf");
serverConfig.SetSdfFile(common::joinPaths(PROJECT_SOURCE_PATH,
"/test/worlds/shapes.sdf"));
chapulina marked this conversation as resolved.
Show resolved Hide resolved

sdf::ElementPtr sdf(new sdf::Element);
sdf->SetName("plugin");
Expand Down Expand Up @@ -338,8 +338,8 @@ TEST_P(ServerFixture, IGN_UTILS_TEST_DISABLED_ON_WIN32(SdfServerConfig))
EXPECT_FALSE(serverConfig.SdfString().empty());

// Setting the SDF file should override the string.
serverConfig.SetSdfFile(std::string(PROJECT_SOURCE_PATH) +
"/test/worlds/shapes.sdf");
serverConfig.SetSdfFile(common::joinPaths(PROJECT_SOURCE_PATH,
"/test/worlds/shapes.sdf"));
EXPECT_FALSE(serverConfig.SdfFile().empty());
EXPECT_TRUE(serverConfig.SdfString().empty());

Expand Down Expand Up @@ -407,8 +407,7 @@ TEST_P(ServerFixture, IGN_UTILS_TEST_DISABLED_ON_WIN32(SdfRootServerConfig))
/////////////////////////////////////////////////
TEST_P(ServerFixture, IGN_UTILS_TEST_DISABLED_ON_WIN32(ServerConfigLogRecord))
{
auto logPath = common::joinPaths(
std::string(PROJECT_BINARY_PATH), "test_log_path");
auto logPath = common::joinPaths(PROJECT_BINARY_PATH, "test_log_path");
auto logFile = common::joinPaths(logPath, "state.tlog");
auto compressedFile = logPath + ".zip";

Expand Down Expand Up @@ -447,8 +446,7 @@ TEST_P(ServerFixture, IGN_UTILS_TEST_DISABLED_ON_WIN32(ServerConfigLogRecord))
TEST_P(ServerFixture,
IGN_UTILS_TEST_DISABLED_ON_WIN32(ServerConfigLogRecordCompress))
{
auto logPath = common::joinPaths(
std::string(PROJECT_BINARY_PATH), "test_log_path");
auto logPath = common::joinPaths(PROJECT_BINARY_PATH, "test_log_path");
auto logFile = common::joinPaths(logPath, "state.tlog");
auto compressedFile = logPath + ".zip";

Expand Down Expand Up @@ -480,8 +478,8 @@ TEST_P(ServerFixture, SdfStringServerConfig)
{
ignition::gazebo::ServerConfig serverConfig;

serverConfig.SetSdfFile(std::string(PROJECT_SOURCE_PATH) +
"/test/worlds/shapes.sdf");
serverConfig.SetSdfFile(common::joinPaths(PROJECT_SOURCE_PATH,
"/test/worlds/shapes.sdf"));
EXPECT_FALSE(serverConfig.SdfFile().empty());
EXPECT_TRUE(serverConfig.SdfString().empty());

Expand Down Expand Up @@ -796,8 +794,8 @@ TEST_P(ServerFixture, IGN_UTILS_TEST_DISABLED_ON_WIN32(AddSystemWhileRunning))
{
ignition::gazebo::ServerConfig serverConfig;

serverConfig.SetSdfFile(std::string(PROJECT_SOURCE_PATH) +
"/test/worlds/shapes.sdf");
serverConfig.SetSdfFile(common::joinPaths(PROJECT_SOURCE_PATH,
"/test/worlds/shapes.sdf"));

gazebo::Server server(serverConfig);
EXPECT_FALSE(server.Running());
Expand Down Expand Up @@ -844,8 +842,8 @@ TEST_P(ServerFixture, IGN_UTILS_TEST_DISABLED_ON_WIN32(AddSystemAfterLoad))
{
ignition::gazebo::ServerConfig serverConfig;

serverConfig.SetSdfFile(std::string(PROJECT_SOURCE_PATH) +
"/test/worlds/shapes.sdf");
serverConfig.SetSdfFile(common::joinPaths(PROJECT_SOURCE_PATH,
"/test/worlds/shapes.sdf"));

gazebo::Server server(serverConfig);
EXPECT_FALSE(server.Running());
Expand Down Expand Up @@ -917,8 +915,8 @@ TEST_P(ServerFixture, Seed)
TEST_P(ServerFixture, IGN_UTILS_TEST_DISABLED_ON_WIN32(ResourcePath))
{
ignition::common::setenv("IGN_GAZEBO_RESOURCE_PATH",
(std::string(PROJECT_SOURCE_PATH) + "/test/worlds:" +
std::string(PROJECT_SOURCE_PATH) + "/test/worlds/models").c_str());
(common::joinPaths(PROJECT_SOURCE_PATH, "/test/worlds:") +
common::joinPaths(PROJECT_SOURCE_PATH, "/test/worlds/models")).c_str());

ServerConfig serverConfig;
serverConfig.SetSdfFile("resource_paths.sdf");
Expand Down Expand Up @@ -1172,6 +1170,32 @@ TEST_P(ServerFixture, ResolveResourcePaths)
"include_nested", "model.sdf"), true);
}

/////////////////////////////////////////////////
TEST_P(ServerFixture, Stop)
{
// Start server
ServerConfig serverConfig;
serverConfig.SetUpdateRate(10000);
serverConfig.SetSdfFile(common::joinPaths((PROJECT_SOURCE_PATH),
"/test/worlds/shapes.sdf"));

gazebo::Server server(serverConfig);

// The simulation runner should not be running.
EXPECT_FALSE(*server.Running(0));
EXPECT_FALSE(server.Running());

// Run the server.
EXPECT_TRUE(server.Run(false, 0, false));
EXPECT_TRUE(*server.Running(0));
EXPECT_TRUE(server.Running());

// Stop the server
server.Stop();
EXPECT_FALSE(*server.Running(0));
EXPECT_FALSE(server.Running());
}

// Run multiple times. We want to make sure that static globals don't cause
// problems.
INSTANTIATE_TEST_SUITE_P(ServerRepeat, ServerFixture, ::testing::Range(1, 2));