test: Check that notifyd messages actually change the database
authorVolker Lendecke <vl@samba.org>
Fri, 23 Oct 2020 13:14:21 +0000 (15:14 +0200)
committerJeremy Allison <jra@samba.org>
Sat, 24 Oct 2020 07:20:17 +0000 (07:20 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat Oct 24 07:20:17 UTC 2020 on sn-devel-184

source3/smbd/notifyd/test_notifyd.c
source3/smbd/notifyd/wscript_build

index c9d223fdd53b8e04199b20aff0a816c76aa3fc86..431da9be3e1397bca9c4b8b3f0a8788bc61030fe 100644 (file)
@@ -231,6 +231,86 @@ static bool test_notifyd_trigger1(struct torture_context *tctx)
        return true;
 }
 
+struct notifyd_have_state {
+       struct server_id self;
+       bool found;
+};
+
+static bool notifyd_have_fn(
+       const char *path,
+       struct server_id server,
+       const struct notify_instance *instance,
+       void *private_data)
+{
+       struct notifyd_have_state *state = private_data;
+       state->found |= server_id_equal(&server, &state->self);
+       return true;
+}
+
+static bool notifyd_have_self(struct messaging_context *msg_ctx)
+{
+       struct notifyd_have_state state = {
+               .self = messaging_server_id(msg_ctx),
+       };
+       NTSTATUS status;
+
+       status = notify_walk(msg_ctx, notifyd_have_fn, &state);
+       if (!NT_STATUS_IS_OK(status)) {
+               return false;
+       }
+       return state.found;
+}
+
+static bool test_notifyd_dbtest1(struct torture_context *tctx)
+{
+       struct tevent_context *ev = tctx->ev;
+       struct messaging_context *msg_ctx = NULL;
+       struct tevent_req *req = NULL;
+       struct server_id_db *names = NULL;
+       struct server_id notifyd;
+       NTSTATUS status;
+       bool ok;
+
+       /*
+        * Make sure fcn_wait_send adds us to the notifyd internal
+        * database and that cancelling the fcn request removes us
+        * again.
+        */
+
+       lp_load_global(tctx->lp_ctx->szConfigFile);
+
+       msg_ctx = messaging_init(tctx, ev);
+       torture_assert_not_null(tctx, msg_ctx, "messaging_init");
+
+       names = messaging_names_db(msg_ctx);
+       ok = server_id_db_lookup_one(names, "notify-daemon", &notifyd);
+       torture_assert(tctx, ok, "server_id_db_lookup_one");
+
+       req = fcn_wait_send(
+               msg_ctx, ev, msg_ctx, notifyd, "/x", UINT32_MAX, UINT32_MAX);
+       torture_assert_not_null(tctx, req, "fcn_wait_send");
+
+       ok = notifyd_have_self(msg_ctx);
+       torture_assert(tctx, ok, "notifyd_have_self");
+
+       ok = tevent_req_cancel(req);
+       torture_assert(tctx, ok, "tevent_req_cancel");
+
+       ok = tevent_req_poll(req, ev);
+       torture_assert(tctx, ok, "tevent_req_poll");
+
+       status = fcn_wait_recv(req, NULL, NULL, NULL, NULL);
+       torture_assert_ntstatus_equal(
+               tctx, status, NT_STATUS_CANCELLED, "fcn_wait_recv");
+       TALLOC_FREE(req);
+
+       ok = notifyd_have_self(msg_ctx);
+       torture_assert(tctx, !ok, "tevent_req_poll");
+       TALLOC_FREE(msg_ctx);
+
+       return true;
+}
+
 NTSTATUS torture_notifyd_init(TALLOC_CTX *mem_ctx);
 NTSTATUS torture_notifyd_init(TALLOC_CTX *mem_ctx)
 {
@@ -249,6 +329,11 @@ NTSTATUS torture_notifyd_init(TALLOC_CTX *mem_ctx)
                goto fail;
        }
 
+       tcase = torture_suite_add_simple_test(
+               suite, "dbtest1", test_notifyd_dbtest1);
+       if (tcase == NULL) {
+               goto fail;
+       }
        suite->description = "notifyd unit tests";
 
        ok = torture_register_suite(mem_ctx, suite);
index cd56ba7763f54e15fe3173a94b02e157cb2d7f8c..6880a314a6f517066d5ee4c28f8e9ecd91942305 100644 (file)
@@ -32,7 +32,7 @@ bld.SAMBA3_BINARY('notifydd',
                   ''')
 
 TORTURE_NOTIFYD_SOURCE='test_notifyd.c'
-TORTURE_NOTIFYD_DEPS='fcn_wait'
+TORTURE_NOTIFYD_DEPS='fcn_wait notifyd_db'
 
 bld.SAMBA_MODULE('TORTURE_NOTIFYD',
        source=TORTURE_NOTIFYD_SOURCE,