summaryrefslogtreecommitdiff
path: root/ctdb/tests
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2017-11-03 16:00:04 +1100
committerAmitay Isaacs <amitay@samba.org>2017-11-07 03:53:27 +0100
commitad8d72091e2e8769c1073bccece699e4da412f57 (patch)
tree7a29466dd91d417fa36b023cea70be9c2690ecbf /ctdb/tests
parent4b652c1527afe7eff4075c95946abfa114d74015 (diff)
downloadsamba-ad8d72091e2e8769c1073bccece699e4da412f57.tar.gz
ctdb-common: Fix stale socket removal
Sockets need to be created from sock_daemon_run_send(). This means that stale socket removal can depend on the PID file context being initialised. Also fix associated test. Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb/tests')
-rwxr-xr-xctdb/tests/cunit/sock_daemon_test_001.sh1
-rw-r--r--ctdb/tests/src/sock_daemon_test.c52
2 files changed, 45 insertions, 8 deletions
diff --git a/ctdb/tests/cunit/sock_daemon_test_001.sh b/ctdb/tests/cunit/sock_daemon_test_001.sh
index 1d2607f36ea..58742755d0d 100755
--- a/ctdb/tests/cunit/sock_daemon_test_001.sh
+++ b/ctdb/tests/cunit/sock_daemon_test_001.sh
@@ -24,6 +24,7 @@ result_filter ()
ok <<EOF
test1[PID]: listening on $sockpath
+test1[PID]: Shutting down
EOF
unit_test sock_daemon_test "$pidfile" "$sockpath" 1
diff --git a/ctdb/tests/src/sock_daemon_test.c b/ctdb/tests/src/sock_daemon_test.c
index 95b0909b78e..bbb792753e1 100644
--- a/ctdb/tests/src/sock_daemon_test.c
+++ b/ctdb/tests/src/sock_daemon_test.c
@@ -32,6 +32,42 @@
#include "common/sock_daemon.c"
#include "common/sock_io.c"
+struct dummy_wait_state {
+};
+
+static struct tevent_req *dummy_wait_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ void *private_data)
+{
+ struct tevent_req *req;
+ struct dummy_wait_state *state;
+ const char *sockpath = (const char *)private_data;
+ struct stat st;
+ int ret;
+
+ ret = stat(sockpath, &st);
+ assert(ret == 0);
+ assert(S_ISSOCK(st.st_mode));
+
+ req = tevent_req_create(mem_ctx, &state, struct dummy_wait_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ tevent_req_done(req);
+ return tevent_req_post(req, ev);
+}
+
+static bool dummy_wait_recv(struct tevent_req *req, int *perr)
+{
+ return true;
+}
+
+static struct sock_daemon_funcs test1_funcs = {
+ .wait_send = dummy_wait_send,
+ .wait_recv = dummy_wait_recv,
+};
+
static struct tevent_req *dummy_read_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct sock_client_context *client,
@@ -63,12 +99,13 @@ static struct sock_socket_funcs dummy_socket_funcs = {
static void test1(TALLOC_CTX *mem_ctx, const char *pidfile,
const char *sockpath)
{
+ struct tevent_context *ev;
struct sock_daemon_context *sockd;
struct stat st;
int ret;
ret = sock_daemon_setup(mem_ctx, "test1", "file:", "NOTICE",
- NULL, NULL, &sockd);
+ &test1_funcs, discard_const(sockpath), &sockd);
assert(ret == 0);
assert(sockd != NULL);
@@ -79,16 +116,15 @@ static void test1(TALLOC_CTX *mem_ctx, const char *pidfile,
assert(ret == 0);
ret = stat(sockpath, &st);
- assert(ret == 0);
- assert(S_ISSOCK(st.st_mode));
+ assert(ret == -1);
- talloc_free(sockd);
+ ev = tevent_context_init(mem_ctx);
+ assert(ev != NULL);
- ret = stat(pidfile, &st);
- assert(ret == -1);
+ ret = sock_daemon_run(ev, sockd, NULL, false, false, -1);
+ assert(ret == 0);
- ret = stat(sockpath, &st);
- assert(ret == -1);
+ talloc_free(mem_ctx);
}
/*