Skip to content

Commit

Permalink
Added test that fails connecting to a socket after n tries
Browse files Browse the repository at this point in the history
  • Loading branch information
fmauch committed Sep 4, 2023
1 parent c09bcf9 commit 4b99755
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
8 changes: 8 additions & 0 deletions tests/test_dashboard_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ TEST_F(DashboardClientTest, set_receive_timeout)
}
}

TEST_F(DashboardClientTest, connect_non_running_robot)
{
std::unique_ptr<DashboardClient> dashboard_client;
// We use an IP address on the integration_test's subnet
dashboard_client.reset(new DashboardClient("192.168.56.123"));
EXPECT_FALSE(dashboard_client->connect(2, std::chrono::milliseconds(500)));
}

int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
Expand Down
11 changes: 11 additions & 0 deletions tests/test_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ TEST_F(PipelineTest, consumer_pipeline)
pipeline_->stop();
}

TEST_F(PipelineTest, connect_non_connected_robot)
{
stream_.reset(new comm::URStream<rtde_interface::RTDEPackage>("127.0.0.1", 12321));
producer_.reset(new comm::URProducer<rtde_interface::RTDEPackage>(*stream_.get(), *parser_.get()));
TestConsumer consumer;
pipeline_.reset(
new comm::Pipeline<rtde_interface::RTDEPackage>(*producer_.get(), &consumer, "RTDE_PIPELINE", notifier_));

EXPECT_THROW(pipeline_->init(2, std::chrono::milliseconds(500)), UrException);
}

int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
Expand Down
13 changes: 12 additions & 1 deletion tests/test_producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,20 @@ TEST_F(ProducerTest, get_data_package)
producer.stopProducer();
}

TEST_F(ProducerTest, connect_non_connected_robot)
{
comm::URStream<rtde_interface::RTDEPackage> stream("127.0.0.1", 12321);
std::vector<std::string> recipe = { "timestamp" };
rtde_interface::RTDEParser parser(recipe);
parser.setProtocolVersion(2);
comm::URProducer<rtde_interface::RTDEPackage> producer(stream, parser);

EXPECT_THROW(producer.setupProducer(2, std::chrono::milliseconds(500)), UrException);
}

int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}
}
9 changes: 9 additions & 0 deletions tests/test_rtde_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <gtest/gtest.h>
#include <cmath>
#include "ur_client_library/exceptions.h"

#include <ur_client_library/rtde/rtde_client.h>

Expand Down Expand Up @@ -346,6 +347,14 @@ TEST_F(RTDEClientTest, output_recipe_without_timestamp)
EXPECT_FALSE(it == actual_output_recipe_from_vector.end());
}

TEST_F(RTDEClientTest, connect_non_running_robot)
{
// We use an IP address on the integration_test's subnet
client_.reset(
new rtde_interface::RTDEClient("192.168.56.123", notifier_, resources_output_recipe_, resources_input_recipe_));
EXPECT_THROW(client_->init(2, std::chrono::milliseconds(500)), UrException);
}

int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
Expand Down
7 changes: 7 additions & 0 deletions tests/test_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ TEST_F(StreamTest, write_data_package)
EXPECT_EQ(send_message, received_message_);
}

TEST_F(StreamTest, connect_non_connected_robot)
{
comm::URStream<rtde_interface::RTDEPackage> stream("127.0.0.1", 12321);
stream.setReconnectionTime(std::chrono::milliseconds(500));
EXPECT_FALSE(stream.connect(2));
}

int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
Expand Down
18 changes: 15 additions & 3 deletions tests/test_tcp_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
// -- END LICENSE BLOCK ------------------------------------------------

#include <gtest/gtest.h>
#include <chrono>
#include <condition_variable>
#include <cstddef>

#include <ur_client_library/comm/tcp_socket.h>
#include <ur_client_library/comm/tcp_server.h>
Expand Down Expand Up @@ -101,15 +103,16 @@ class TCPSocketTest : public ::testing::Test
class Client : public comm::TCPSocket
{
public:
Client(int port)
Client(int port, const std::string& ip = "127.0.0.1", const size_t max_num_tries = 0)
{
port_ = port;
ip_ = ip;
max_num_tries_ = max_num_tries;
}

bool setup()
{
std::string ip = "127.0.0.1";
return TCPSocket::setup(ip, port_);
return TCPSocket::setup(ip_, port_, max_num_tries_);
}

void setupClientBeforeServer()
Expand Down Expand Up @@ -145,6 +148,8 @@ class TCPSocketTest : public ::testing::Test
private:
std::thread client_setup_thread_;
int port_;
std::string ip_;
size_t max_num_tries_;
bool done_setting_up_client_;

void setupClient(int port)
Expand Down Expand Up @@ -341,6 +346,13 @@ TEST_F(TCPSocketTest, setup_while_client_is_connected)
EXPECT_FALSE(client_->setup());
}

TEST_F(TCPSocketTest, connect_non_running_robot)
{
Client client(12321, "127.0.0.1", 2);
client.setReconnectionTime(std::chrono::milliseconds(500));
EXPECT_FALSE(client.setup());
}

int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit 4b99755

Please sign in to comment.