Skip to content

Commit 174e0b5

Browse files
author
Felix Exner
committed
Fix tests
1 parent 1d4c0fb commit 174e0b5

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

tests/test_dashboard_client.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <ur_client_library/exceptions.h>
3333
#include <chrono>
3434
#include <thread>
35+
#include "ur_client_library/comm/tcp_socket.h"
3536
#include "ur_client_library/ur/version_information.h"
3637
#define private public
3738
#include <ur_client_library/ur/dashboard_client.h>
@@ -208,7 +209,14 @@ TEST_F(DashboardClientTest, connect_non_running_robot)
208209
std::unique_ptr<DashboardClient> dashboard_client;
209210
// We use an IP address on the integration_test's subnet
210211
dashboard_client.reset(new DashboardClient("192.168.56.123"));
212+
auto start = std::chrono::system_clock::now();
211213
EXPECT_FALSE(dashboard_client->connect(2, std::chrono::milliseconds(500)));
214+
auto end = std::chrono::system_clock::now();
215+
auto elapsed = end - start;
216+
// This is only a rough estimate, obviously.
217+
// Since this isn't done on the loopback device, trying to open a socket on a non-existing address
218+
// takes considerably longer.
219+
EXPECT_LT(elapsed, 2 * comm::TCPSocket::DEFAULT_RECONNECTION_TIME);
212220
}
213221

214222
int main(int argc, char* argv[])

tests/test_pipeline.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,12 @@ TEST_F(PipelineTest, connect_non_connected_robot)
242242
pipeline_.reset(
243243
new comm::Pipeline<rtde_interface::RTDEPackage>(*producer_.get(), &consumer, "RTDE_PIPELINE", notifier_));
244244

245+
auto start = std::chrono::system_clock::now();
245246
EXPECT_THROW(pipeline_->init(2, std::chrono::milliseconds(500)), UrException);
247+
auto end = std::chrono::system_clock::now();
248+
auto elapsed = end - start;
249+
// This is only a rough estimate, obviously
250+
EXPECT_LT(elapsed, std::chrono::milliseconds(1500));
246251
}
247252

248253
int main(int argc, char* argv[])

tests/test_producer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// -- END LICENSE BLOCK ------------------------------------------------
3030

3131
#include <gtest/gtest.h>
32+
#include <chrono>
3233
#include <condition_variable>
3334

3435
#include <ur_client_library/comm/producer.h>
@@ -127,7 +128,12 @@ TEST_F(ProducerTest, connect_non_connected_robot)
127128
parser.setProtocolVersion(2);
128129
comm::URProducer<rtde_interface::RTDEPackage> producer(stream, parser);
129130

131+
auto start = std::chrono::system_clock::now();
130132
EXPECT_THROW(producer.setupProducer(2, std::chrono::milliseconds(500)), UrException);
133+
auto end = std::chrono::system_clock::now();
134+
auto elapsed = end - start;
135+
// This is only a rough estimate, obviously
136+
EXPECT_LT(elapsed, std::chrono::milliseconds(1500));
131137
}
132138

133139
int main(int argc, char* argv[])

tests/test_rtde_client.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,14 @@ TEST_F(RTDEClientTest, connect_non_running_robot)
352352
// We use an IP address on the integration_test's subnet
353353
client_.reset(
354354
new rtde_interface::RTDEClient("192.168.56.123", notifier_, resources_output_recipe_, resources_input_recipe_));
355+
auto start = std::chrono::system_clock::now();
355356
EXPECT_THROW(client_->init(2, std::chrono::milliseconds(500)), UrException);
357+
auto end = std::chrono::system_clock::now();
358+
auto elapsed = end - start;
359+
// This is only a rough estimate, obviously.
360+
// Since this isn't done on the loopback device, trying to open a socket on a non-existing address
361+
// takes considerably longer.
362+
EXPECT_LT(elapsed, 2 * comm::TCPSocket::DEFAULT_RECONNECTION_TIME);
356363
}
357364

358365
int main(int argc, char* argv[])

tests/test_stream.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,12 @@ TEST_F(StreamTest, write_data_package)
324324
TEST_F(StreamTest, connect_non_connected_robot)
325325
{
326326
comm::URStream<rtde_interface::RTDEPackage> stream("127.0.0.1", 12321);
327+
auto start = std::chrono::system_clock::now();
327328
EXPECT_FALSE(stream.connect(2, std::chrono::milliseconds(500)));
329+
auto end = std::chrono::system_clock::now();
330+
auto elapsed = end - start;
331+
// This is only a rough estimate, obviously
332+
EXPECT_LT(elapsed, std::chrono::milliseconds(1500));
328333
}
329334

330335
int main(int argc, char* argv[])

tests/test_tcp_socket.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include <condition_variable>
3434
#include <cstddef>
3535

36+
// This file adds a test for a deprecated function. To avoid a compiler warning in CI (where we want
37+
// to treat warnings as errors) we suppress the warning inside this file.
38+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
3639
#include <ur_client_library/comm/tcp_socket.h>
3740
#include <ur_client_library/comm/tcp_server.h>
3841
#include "ur_client_library/types.h"
@@ -156,7 +159,7 @@ class TCPSocketTest : public ::testing::Test
156159
std::chrono::milliseconds reconnection_time = std::chrono::seconds(10))
157160
{
158161
std::string ip = "127.0.0.1";
159-
TCPSocket::setup(ip, port);
162+
TCPSocket::setup(ip, port, max_num_tries, reconnection_time);
160163
done_setting_up_client_ = true;
161164
}
162165
};
@@ -349,7 +352,18 @@ TEST_F(TCPSocketTest, setup_while_client_is_connected)
349352
TEST_F(TCPSocketTest, connect_non_running_robot)
350353
{
351354
Client client(12321, "127.0.0.1");
355+
auto start = std::chrono::system_clock::now();
352356
EXPECT_FALSE(client.setup(2, std::chrono::milliseconds(500)));
357+
auto end = std::chrono::system_clock::now();
358+
auto elapsed = end - start;
359+
// This is only a rough estimate, obviously
360+
EXPECT_LT(elapsed, std::chrono::milliseconds(1500));
361+
}
362+
363+
TEST_F(TCPSocketTest, test_deprecated_reconnection_time_interface)
364+
{
365+
client_->setReconnectionTime(std::chrono::milliseconds(100));
366+
EXPECT_TRUE(client_->setup(2));
353367
}
354368

355369
int main(int argc, char* argv[])

0 commit comments

Comments
 (0)