ctdb-tests: Try to connect few times before failing in comm_client_test
authorAmitay Isaacs <amitay@gmail.com>
Tue, 10 Nov 2015 03:49:30 +0000 (14:49 +1100)
committerAmitay Isaacs <amitay@samba.org>
Wed, 11 Nov 2015 02:21:22 +0000 (03:21 +0100)
cunit/comm_test_002.sh requires that the comm_server_test is started
before comm_client_test.  Since comm_server_test is started in background,
it's possible for comm_client_test to run before comm_server_test has
bound to the unix domain socket.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/tests/src/comm_client_test.c

index e1ebe1ca33cce0da1181410fc1eafe38a795abbf..8db219e6ee4a78706c84fa06dc4b8b7cb06562b6 100644 (file)
@@ -156,7 +156,7 @@ static void writer_recv(struct tevent_req *req, int *perr)
 static int socket_init(char *sockpath)
 {
        struct sockaddr_un addr;
-       int fd, ret;
+       int fd, ret, i;
        size_t len;
 
        memset(&addr, 0, sizeof(addr));
@@ -168,7 +168,13 @@ static int socket_init(char *sockpath)
        fd = socket(AF_UNIX, SOCK_STREAM, 0);
        assert(fd != -1);
 
-       ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
+       for (i=0; i<5; i++) {
+               ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
+               if (ret == 0) {
+                       break;
+               }
+               sleep(1);
+       }
        assert(ret != -1);
 
        return fd;