Skip to content

Commit 09c6908

Browse files
authored
Do not throw exception in DashboardClient::sendRequest (#249)
I don't know why we changed it to throwing an exception. It doesn't make sense for this function.
1 parent f3ea4e7 commit 09c6908

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/ur/dashboard_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ bool DashboardClient::sendRequest(const std::string& command, const std::string&
160160
bool ret = std::regex_match(response, std::regex(expected));
161161
if (!ret)
162162
{
163-
throw UrException("Expected: " + expected + ", but received: " + response);
163+
URCL_LOG_WARN("Expected: \"%s\", but received: \"%s\"", expected.c_str(), response.c_str());
164164
}
165165
return ret;
166166
}

tests/test_dashboard_client.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,29 @@ TEST_F(DashboardClientTest, connect_non_running_robot)
219219
EXPECT_LT(elapsed, 2 * comm::TCPSocket::DEFAULT_RECONNECTION_TIME);
220220
}
221221

222+
TEST_F(DashboardClientTest, non_expected_result_returns_correctly)
223+
{
224+
ASSERT_TRUE(dashboard_client_->connect());
225+
EXPECT_TRUE(dashboard_client_->commandPowerOff());
226+
227+
// We will not get this answer
228+
EXPECT_FALSE(dashboard_client_->sendRequest("brake release", "non-existing-response"));
229+
230+
// A non-matching answer should throw an exception for this call
231+
EXPECT_THROW(dashboard_client_->sendRequestString("brake release", "non-existing-response"), UrException);
232+
233+
// Waiting for a non-matching answer should return false
234+
// Internally we wait 100ms between each attempt, hence the 300ms wait time
235+
EXPECT_FALSE(
236+
dashboard_client_->waitForReply("brake_release", "non-existing-response", std::chrono::milliseconds(300)));
237+
}
238+
239+
TEST_F(DashboardClientTest, connecting_twice_returns_false)
240+
{
241+
ASSERT_TRUE(dashboard_client_->connect());
242+
EXPECT_FALSE(dashboard_client_->connect());
243+
}
244+
222245
int main(int argc, char* argv[])
223246
{
224247
::testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)