Skip to content

Commit

Permalink
update (dmlc#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
aksnzhy authored Jun 3, 2019
1 parent 01a4cc5 commit 3a11d26
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions tests/cpp/socket_communicator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@ bool start_server();
#include <unistd.h>

TEST(SocketCommunicatorTest, SendAndRecv) {
int pid = fork();
ASSERT_GE(pid, 0);
if (pid > 0) {
EXPECT_TRUE(start_server());
} else {
start_client();
}
std::thread client_thread(start_client);
start_server();
client_thread.join();
}

#else // WIN32

// Win32 doesn't have a fork() equivalent so use threads instead.

#include <windows.h>
#include <winsock2.h>

Expand Down Expand Up @@ -79,21 +73,21 @@ TEST(SocketCommunicatorTest, SendAndRecv) {
#endif // WIN32

void start_client() {
const char * msg = "0123456789";
const char * msg = "123456789";
sleep(1);
SocketSender sender;
sender.AddReceiver("127.0.0.1", 2049, 0);
sender.Connect();
sender.Send(msg, 10, 0);
sender.Send(msg, 9, 0);
sender.Finalize();
}

bool start_server() {
char serbuff[10];
memset(serbuff, '\0', 10);
SocketReceiver receiver;
receiver.Wait("127.0.0.1", 2049, 1, 500);
receiver.Recv(serbuff, 10);
receiver.Wait("127.0.0.1", 2049, 1, 500 * 1024);
receiver.Recv(serbuff, 9);
receiver.Finalize();
return string("0123456789") == string(serbuff);
return string("123456789") == string(serbuff);
}

0 comments on commit 3a11d26

Please sign in to comment.