|
@@ -105,16 +105,32 @@ namespace UnitTest
|
|
|
AZ_Assert(node, "Node is not available.");
|
|
|
return node;
|
|
|
}
|
|
|
- void SpinAppSome()
|
|
|
+ void SpinAppSome(int numberOfTicks = 50)
|
|
|
{
|
|
|
AZ::ComponentApplication* app = nullptr;
|
|
|
AZ::ComponentApplicationBus::BroadcastResult(app, &AZ::ComponentApplicationBus::Events::GetApplication);
|
|
|
AZ_Assert(app, "Application pointer is not available.");
|
|
|
- for (int i = 0; i < 10; ++i)
|
|
|
+ for (int i = 0; i < numberOfTicks; ++i)
|
|
|
{
|
|
|
app->Tick();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ template <typename Future>void SpinAppUntilFuture(Future &future)
|
|
|
+ {
|
|
|
+ AZ::ComponentApplication* app = nullptr;
|
|
|
+ AZ::ComponentApplicationBus::BroadcastResult(app, &AZ::ComponentApplicationBus::Events::GetApplication);
|
|
|
+ AZ_Assert(app, "Application pointer is not available.");
|
|
|
+ constexpr int MaximumTicks = 1000;
|
|
|
+ for (int i = 0; i < MaximumTicks; ++i)
|
|
|
+ {
|
|
|
+ app->Tick();
|
|
|
+ if (future.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
//! Perform a smoke test to check if the ROS2 node is available from ROS2 gem
|
|
@@ -186,7 +202,7 @@ namespace UnitTest
|
|
|
}));
|
|
|
|
|
|
auto future = client->async_send_request(request);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Service call timed out.";
|
|
|
auto response = future.get();
|
|
@@ -217,7 +233,7 @@ namespace UnitTest
|
|
|
}));
|
|
|
|
|
|
auto future = client->async_send_request(request);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Service call timed out.";
|
|
|
auto response = future.get();
|
|
@@ -265,7 +281,7 @@ namespace UnitTest
|
|
|
}));
|
|
|
|
|
|
auto future = client->async_send_request(request);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Service call timed out.";
|
|
|
auto response = future.get();
|
|
@@ -284,7 +300,7 @@ namespace UnitTest
|
|
|
request->filters.bounds.type = simulation_interfaces::msg::Bounds::TYPE_SPHERE;
|
|
|
|
|
|
auto future = client->async_send_request(request);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Service call timed out.";
|
|
|
auto response = future.get();
|
|
|
EXPECT_NE(response->result.result, simulation_interfaces::msg::Result::RESULT_OK);
|
|
@@ -332,7 +348,7 @@ namespace UnitTest
|
|
|
}));
|
|
|
|
|
|
auto future = client->async_send_request(request);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Service call timed out.";
|
|
|
auto response = future.get();
|
|
@@ -361,7 +377,7 @@ namespace UnitTest
|
|
|
request->filters.bounds.type = simulation_interfaces::msg::Bounds::TYPE_BOX;
|
|
|
|
|
|
auto future = client->async_send_request(request);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Service call timed out.";
|
|
|
auto response = future.get();
|
|
@@ -377,7 +393,7 @@ namespace UnitTest
|
|
|
auto client = node->create_client<simulation_interfaces::srv::GetSimulatorFeatures>("/get_simulation_features");
|
|
|
auto request = std::make_shared<simulation_interfaces::srv::GetSimulatorFeatures::Request>();
|
|
|
auto future = client->async_send_request(request);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Service call timed out.";
|
|
|
auto response = future.get();
|
|
|
EXPECT_TRUE(response->features.features.empty()) << "Features vector is not empty.";
|
|
@@ -405,7 +421,7 @@ namespace UnitTest
|
|
|
auto client = node->create_client<simulation_interfaces::srv::GetSimulatorFeatures>("/get_simulation_features");
|
|
|
auto request = std::make_shared<simulation_interfaces::srv::GetSimulatorFeatures::Request>();
|
|
|
auto future = client->async_send_request(request);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Service call timed out.";
|
|
|
auto response = future.get();
|
|
|
ASSERT_FALSE(response->features.features.empty()) << "Features vector is empty.";
|
|
@@ -443,7 +459,7 @@ namespace UnitTest
|
|
|
EXPECT_TRUE(allowRename);
|
|
|
completedCb(AZ::Success("valid_name"));
|
|
|
}));
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Service call timed out.";
|
|
|
auto response = future.get();
|
|
@@ -464,7 +480,7 @@ namespace UnitTest
|
|
|
request->entity_namespace = "test_namespace";
|
|
|
|
|
|
auto future = client->async_send_request(request);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Service call timed out.";
|
|
|
auto response = future.get();
|
|
@@ -486,7 +502,7 @@ namespace UnitTest
|
|
|
request->entity_namespace = "invalid namespace";
|
|
|
|
|
|
auto future = client->async_send_request(request);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Service call timed out.";
|
|
|
auto response = future.get();
|
|
@@ -523,12 +539,12 @@ namespace UnitTest
|
|
|
}));
|
|
|
|
|
|
auto future = client->async_send_goal(*goal);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Action call timed out.";
|
|
|
auto goalHandle = future.get();
|
|
|
ASSERT_NE(goalHandle, nullptr);
|
|
|
auto result = client->async_get_result(goalHandle);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(result);
|
|
|
ASSERT_TRUE(result.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Action call timed out.";
|
|
|
EXPECT_EQ(result.get().result->result.result, simulation_interfaces::msg::Result::RESULT_OK);
|
|
|
}
|
|
@@ -552,12 +568,12 @@ namespace UnitTest
|
|
|
}));
|
|
|
|
|
|
auto future = client->async_send_goal(*goal);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Action call timed out.";
|
|
|
auto goalHandle = future.get();
|
|
|
ASSERT_NE(goalHandle, nullptr);
|
|
|
auto result = client->async_get_result(goalHandle);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(result);
|
|
|
ASSERT_TRUE(result.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Action call timed out.";
|
|
|
EXPECT_EQ(result.get().result->result.result, simulation_interfaces::msg::Result::RESULT_OPERATION_FAILED);
|
|
|
}
|
|
@@ -593,13 +609,13 @@ namespace UnitTest
|
|
|
EXPECT_CALL(mock, CancelStepSimulation());
|
|
|
|
|
|
auto future = client->async_send_goal(*goal);
|
|
|
- SpinAppSome();
|
|
|
+ SpinAppUntilFuture(future);
|
|
|
ASSERT_TRUE(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Action call timed out.";
|
|
|
auto goalHandle = future.get();
|
|
|
ASSERT_NE(goalHandle, nullptr);
|
|
|
- auto cancelFeautre = client->async_cancel_goal(goalHandle);
|
|
|
- SpinAppSome();
|
|
|
- ASSERT_TRUE(cancelFeautre.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Action call timed out.";
|
|
|
+ auto cancelFuture = client->async_cancel_goal(goalHandle);
|
|
|
+ SpinAppUntilFuture(cancelFuture);
|
|
|
+ ASSERT_TRUE(cancelFuture.wait_for(std::chrono::seconds(0)) == std::future_status::ready) << "Action call timed out.";
|
|
|
}
|
|
|
|
|
|
} // namespace UnitTest
|