Skip to content

Commit

Permalink
OMG finally fix why the test is failing sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
LasseRosenow committed Dec 9, 2024
1 parent 3979667 commit 582fea4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/platform/posix/tcp_ip_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static lf_ret_t _TcpIpChannel_server_bind(TcpIpChannel *self) {
// bind the socket to that address
int ret = bind(self->fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
if (ret < 0) {
LF_ERR(NET, "TcpIpChannel: Could not bind to %s:%d", self->host, self->port);
LF_ERR(NET, "TcpIpChannel: Could not bind to %s:%d (errno: %d)", self->host, self->port, errno);
_TcpIpChannel_update_state(self, NETWORK_CHANNEL_STATE_CONNECTION_FAILED);
return LF_ERR;
}
Expand Down Expand Up @@ -576,6 +576,6 @@ void TcpIpChannel_ctor(TcpIpChannel *self, Environment *env, const char *host, u
self->federated_connection = NULL;
self->worker_thread = 0;

_TcpIpChannel_spawn_worker_thread(self);
_TcpIpChannel_reset_socket(self);
_TcpIpChannel_spawn_worker_thread(self);
}
12 changes: 4 additions & 8 deletions test/unit/tcp_channel_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include <inttypes.h>
#include <sys/socket.h>
#include <unistd.h>
#include <arpa/inet.h>

#define MESSAGE_CONTENT "Hello World1234"
#define MESSAGE_CONNECTION_ID 42
#define HOST "127.0.0.1"
#define PORT 8903
#define PORT 9000

Reactor parent;
Environment env;
Expand All @@ -26,25 +27,20 @@ bool server_callback_called = false;
bool client_callback_called = false;

void setUp(void) {
static int port_offset = 0;

/* init environment */
Environment_ctor(&env, NULL);
env.net_bundles = net_bundles;
env.net_bundles_size = 2;

/* init server */
TcpIpChannel_ctor(&_server_tcp_channel, &env, HOST, PORT + port_offset, AF_INET, true);
TcpIpChannel_ctor(&_server_tcp_channel, &env, HOST, PORT, AF_INET, true);

/* init client */
TcpIpChannel_ctor(&_client_tcp_channel, &env, HOST, PORT + port_offset, AF_INET, false);
TcpIpChannel_ctor(&_client_tcp_channel, &env, HOST, PORT, AF_INET, false);

/* init bundles */
FederatedConnectionBundle_ctor(&server_bundle, &parent, server_channel, NULL, NULL, 0, NULL, NULL, 0);
FederatedConnectionBundle_ctor(&client_bundle, &parent, client_channel, NULL, NULL, 0, NULL, NULL, 0);

/* increase port number to prevent issues with bind (the socket gets recreated too fast in the unit test) */
port_offset++;
}

void tearDown(void) {
Expand Down

0 comments on commit 582fea4

Please sign in to comment.