dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone
Blob Blame History Raw
From c5a0909216c406ce3e23d6f41146daf2bb303226 Mon Sep 17 00:00:00 2001
From: Tomas Halman <thalman@redhat.com>
Date: Fri, 19 Jul 2019 13:05:44 +0200
Subject: [PATCH 46/48] BE: Introduce flag for be_ptask_create
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The be_ptask_create has already too many parameters. Lets have flags
parameter to avoid future extending.

Reviewed-by: Pavel Březina <pbrezina@redhat.com>
---
 src/providers/ad/ad_dyndns.c             |  2 +-
 src/providers/ad/ad_machine_pw_renewal.c |  2 +-
 src/providers/ad/ad_subdomains.c         |  2 +-
 src/providers/be_ptask.c                 | 17 +++++-
 src/providers/be_ptask.h                 | 10 ++++
 src/providers/be_ptask_private.h         |  1 +
 src/providers/be_refresh.c               |  2 +-
 src/providers/data_provider_be.c         |  2 +-
 src/providers/ipa/ipa_dyndns.c           |  2 +-
 src/providers/ipa/ipa_subdomains.c       |  2 +-
 src/providers/ldap/ldap_id_cleanup.c     |  2 +-
 src/providers/ldap/ldap_id_enum.c        |  2 +-
 src/providers/ldap/sdap_sudo_shared.c    |  4 +-
 src/tests/cmocka/test_be_ptask.c         | 67 +++++++++++++++---------
 14 files changed, 80 insertions(+), 37 deletions(-)

diff --git a/src/providers/ad/ad_dyndns.c b/src/providers/ad/ad_dyndns.c
index 02ea7f24b..af765b581 100644
--- a/src/providers/ad/ad_dyndns.c
+++ b/src/providers/ad/ad_dyndns.c
@@ -101,7 +101,7 @@ errno_t ad_dyndns_init(struct be_ctx *be_ctx,
     ret = be_ptask_create(ad_opts, be_ctx, period, ptask_first_delay, 0, 0, period,
                           BE_PTASK_OFFLINE_DISABLE, BE_PTASK_SCHEDULE_FROM_LAST, 0,
                           ad_dyndns_update_send, ad_dyndns_update_recv, ad_opts,
-                          "Dyndns update", NULL);
+                          "Dyndns update", 0, NULL);
 
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup ptask "
diff --git a/src/providers/ad/ad_machine_pw_renewal.c b/src/providers/ad/ad_machine_pw_renewal.c
index 47941dfbf..67802c04a 100644
--- a/src/providers/ad/ad_machine_pw_renewal.c
+++ b/src/providers/ad/ad_machine_pw_renewal.c
@@ -388,7 +388,7 @@ errno_t ad_machine_account_password_renewal_init(struct be_ctx *be_ctx,
                           ad_machine_account_password_renewal_send,
                           ad_machine_account_password_renewal_recv,
                           renewal_data,
-                          "AD machine account password renewal", NULL);
+                          "AD machine account password renewal", 0, NULL);
     if (ret != EOK) {
         DEBUG(SSSDBG_OP_FAILURE, "be_ptask_create failed.\n");
         goto done;
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
index 2510498da..0f46b46ad 100644
--- a/src/providers/ad/ad_subdomains.c
+++ b/src/providers/ad/ad_subdomains.c
@@ -2070,7 +2070,7 @@ errno_t ad_subdomains_init(TALLOC_CTX *mem_ctx,
                           BE_PTASK_SCHEDULE_FROM_LAST,
                           0,
                           ad_subdomains_ptask_send, ad_subdomains_ptask_recv, sd_ctx,
-                          "Subdomains Refresh", NULL);
+                          "Subdomains Refresh", 0, NULL);
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup ptask "
               "[%d]: %s\n", ret, sss_strerror(ret));
diff --git a/src/providers/be_ptask.c b/src/providers/be_ptask.c
index 32d9a03ce..56c9c82fe 100644
--- a/src/providers/be_ptask.c
+++ b/src/providers/be_ptask.c
@@ -208,6 +208,12 @@ static void be_ptask_schedule(struct be_ptask *task,
         delay = task->enabled_delay;
         break;
     case BE_PTASK_PERIOD:
+        if (task->flags & BE_PTASK_NO_PERIODIC) {
+            /* Periodic task is disabled, */
+            /* only online/offline change can cause some activity. */
+            return;
+        }
+
         delay = task->period;
 
         if (backoff_allowed(task) && task->period * 2 <= task->max_backoff) {
@@ -269,16 +275,21 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
                         be_ptask_recv_t recv_fn,
                         void *pvt,
                         const char *name,
+                        uint32_t flags,
                         struct be_ptask **_task)
 {
     struct be_ptask *task = NULL;
     errno_t ret;
 
-    if (be_ctx == NULL || period == 0 || send_fn == NULL || recv_fn == NULL
+    if (be_ctx == NULL || send_fn == NULL || recv_fn == NULL
         || name == NULL) {
         return EINVAL;
     }
 
+    if (period == 0 && (flags & BE_PTASK_NO_PERIODIC) == 0) {
+        return EINVAL;
+    }
+
     task = talloc_zero(mem_ctx, struct be_ptask);
     if (task == NULL) {
         ret = ENOMEM;
@@ -306,6 +317,7 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
         goto done;
     }
 
+    task->flags = flags;
     task->enabled = true;
 
     talloc_set_destructor((TALLOC_CTX*)task, be_ptask_destructor);
@@ -451,6 +463,7 @@ errno_t be_ptask_create_sync(TALLOC_CTX *mem_ctx,
                              be_ptask_sync_t fn,
                              void *pvt,
                              const char *name,
+                             uint32_t flags,
                              struct be_ptask **_task)
 {
     errno_t ret;
@@ -469,7 +482,7 @@ errno_t be_ptask_create_sync(TALLOC_CTX *mem_ctx,
                           enabled_delay, random_offset, timeout, offline,
                           BE_PTASK_SCHEDULE_FROM_LAST,
                           max_backoff, be_ptask_sync_send, be_ptask_sync_recv,
-                          ctx, name, _task);
+                          ctx, name, flags, _task);
     if (ret != EOK) {
         goto done;
     }
diff --git a/src/providers/be_ptask.h b/src/providers/be_ptask.h
index c23278e88..a33443965 100644
--- a/src/providers/be_ptask.h
+++ b/src/providers/be_ptask.h
@@ -30,6 +30,14 @@ struct be_ctx;
 
 struct be_ptask;
 
+/* be_ptask flags */
+
+/**
+ * Do not schedule periodic task. This flag is useful for tasks that
+ * should be performend only when there is offline/online change.
+ */
+#define BE_PTASK_NO_PERIODIC         0x0001
+
 /**
  * Defines how should task behave when back end is offline.
  */
@@ -127,6 +135,7 @@ errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
                         be_ptask_recv_t recv_fn,
                         void *pvt,
                         const char *name,
+                        uint32_t flags,
                         struct be_ptask **_task);
 
 errno_t be_ptask_create_sync(TALLOC_CTX *mem_ctx,
@@ -141,6 +150,7 @@ errno_t be_ptask_create_sync(TALLOC_CTX *mem_ctx,
                              be_ptask_sync_t fn,
                              void *pvt,
                              const char *name,
+                             uint32_t flags,
                              struct be_ptask **_task);
 
 void be_ptask_enable(struct be_ptask *task);
diff --git a/src/providers/be_ptask_private.h b/src/providers/be_ptask_private.h
index e89105f95..496a2f9ae 100644
--- a/src/providers/be_ptask_private.h
+++ b/src/providers/be_ptask_private.h
@@ -43,6 +43,7 @@ struct be_ptask {
     time_t last_execution;  /* last time when send was called */
     struct tevent_req *req; /* active tevent request */
     struct tevent_timer *timer; /* active tevent timer */
+    uint32_t flags;
     bool enabled;
 };
 
diff --git a/src/providers/be_refresh.c b/src/providers/be_refresh.c
index 8f50e231d..687d3f022 100644
--- a/src/providers/be_refresh.c
+++ b/src/providers/be_refresh.c
@@ -177,7 +177,7 @@ static errno_t be_refresh_ctx_init(struct be_ctx *be_ctx,
                               BE_PTASK_SCHEDULE_FROM_NOW,
                               0,
                               be_refresh_send, be_refresh_recv,
-                              ctx, "Refresh Records", NULL);
+                              ctx, "Refresh Records", 0, NULL);
         if (ret != EOK) {
             DEBUG(SSSDBG_FATAL_FAILURE,
                   "Unable to initialize refresh periodic task [%d]: %s\n",
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index 877841055..f21669b8c 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -133,7 +133,7 @@ void be_mark_offline(struct be_ctx *ctx)
                                    BE_PTASK_OFFLINE_EXECUTE,
                                    3600 /* max_backoff */,
                                    try_to_go_online,
-                                   ctx, "Check if online (periodic)",
+                                   ctx, "Check if online (periodic)", 0,
                                    &ctx->check_if_online_ptask);
         if (ret != EOK) {
             DEBUG(SSSDBG_FATAL_FAILURE,
diff --git a/src/providers/ipa/ipa_dyndns.c b/src/providers/ipa/ipa_dyndns.c
index 8e8ff5a4f..27852c2e2 100644
--- a/src/providers/ipa/ipa_dyndns.c
+++ b/src/providers/ipa/ipa_dyndns.c
@@ -78,7 +78,7 @@ errno_t ipa_dyndns_init(struct be_ctx *be_ctx,
                           BE_PTASK_SCHEDULE_FROM_LAST,
                           0,
                           ipa_dyndns_update_send, ipa_dyndns_update_recv, ctx,
-                          "Dyndns update", NULL);
+                          "Dyndns update", 0, NULL);
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup ptask "
               "[%d]: %s\n", ret, sss_strerror(ret));
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
index 3a17c851d..13e49c5c0 100644
--- a/src/providers/ipa/ipa_subdomains.c
+++ b/src/providers/ipa/ipa_subdomains.c
@@ -3138,7 +3138,7 @@ errno_t ipa_subdomains_init(TALLOC_CTX *mem_ctx,
                           BE_PTASK_SCHEDULE_FROM_LAST,
                           0,
                           ipa_subdomains_ptask_send, ipa_subdomains_ptask_recv, sd_ctx,
-                          "Subdomains Refresh", NULL);
+                          "Subdomains Refresh", 0, NULL);
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup ptask "
               "[%d]: %s\n", ret, sss_strerror(ret));
diff --git a/src/providers/ldap/ldap_id_cleanup.c b/src/providers/ldap/ldap_id_cleanup.c
index e50fb0f22..df56f4da4 100644
--- a/src/providers/ldap/ldap_id_cleanup.c
+++ b/src/providers/ldap/ldap_id_cleanup.c
@@ -88,7 +88,7 @@ errno_t ldap_setup_cleanup(struct sdap_id_ctx *id_ctx,
     ret = be_ptask_create_sync(sdom, id_ctx->be, period, first_delay,
                                5 /* enabled delay */, 0 /* random offset */,
                                period /* timeout */, BE_PTASK_OFFLINE_SKIP, 0,
-                               ldap_cleanup_task, cleanup_ctx, name,
+                               ldap_cleanup_task, cleanup_ctx, name, 0,
                                &sdom->cleanup_task);
     if (ret != EOK) {
         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize cleanup periodic "
diff --git a/src/providers/ldap/ldap_id_enum.c b/src/providers/ldap/ldap_id_enum.c
index 062185c55..2137f6821 100644
--- a/src/providers/ldap/ldap_id_enum.c
+++ b/src/providers/ldap/ldap_id_enum.c
@@ -102,7 +102,7 @@ errno_t ldap_setup_enumeration(struct be_ctx *be_ctx,
                           BE_PTASK_SCHEDULE_FROM_LAST,
                           0,                        /* max_backoff */
                           send_fn, recv_fn,
-                          ectx, "enumeration", &sdom->enum_task);
+                          ectx, "enumeration", 0, &sdom->enum_task);
     if (ret != EOK) {
         DEBUG(SSSDBG_FATAL_FAILURE,
               "Unable to initialize enumeration periodic task\n");
diff --git a/src/providers/ldap/sdap_sudo_shared.c b/src/providers/ldap/sdap_sudo_shared.c
index a00d8e6a9..59356bd44 100644
--- a/src/providers/ldap/sdap_sudo_shared.c
+++ b/src/providers/ldap/sdap_sudo_shared.c
@@ -94,7 +94,7 @@ sdap_sudo_ptask_setup_generic(struct be_ctx *be_ctx,
                               BE_PTASK_SCHEDULE_FROM_LAST,
                               0,
                               full_send_fn, full_recv_fn, pvt,
-                              "SUDO Full Refresh", NULL);
+                              "SUDO Full Refresh", 0, NULL);
         if (ret != EOK) {
             DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup full refresh ptask "
                   "[%d]: %s\n", ret, sss_strerror(ret));
@@ -113,7 +113,7 @@ sdap_sudo_ptask_setup_generic(struct be_ctx *be_ctx,
                               BE_PTASK_SCHEDULE_FROM_LAST,
                               0,
                               smart_send_fn, smart_recv_fn, pvt,
-                              "SUDO Smart Refresh", NULL);
+                              "SUDO Smart Refresh", 0, NULL);
         if (ret != EOK) {
             DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup smart refresh ptask "
                   "[%d]: %s\n", ret, sss_strerror(ret));
diff --git a/src/tests/cmocka/test_be_ptask.c b/src/tests/cmocka/test_be_ptask.c
index 03b1165bb..ac8c0767f 100644
--- a/src/tests/cmocka/test_be_ptask.c
+++ b/src/tests/cmocka/test_be_ptask.c
@@ -306,7 +306,7 @@ void test_be_ptask_create_einval_be(void **state)
     ret = be_ptask_create(test_ctx, NULL, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, NULL, "Test ptask", &ptask);
+                          test_be_ptask_recv, NULL, "Test ptask", 0, &ptask);
     assert_int_equal(ret, EINVAL);
     assert_null(ptask);
 }
@@ -320,7 +320,7 @@ void test_be_ptask_create_einval_period(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, 0, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, NULL, "Test ptask", &ptask);
+                          test_be_ptask_recv, NULL, "Test ptask", 0, &ptask);
     assert_int_equal(ret, EINVAL);
     assert_null(ptask);
 }
@@ -334,7 +334,7 @@ void test_be_ptask_create_einval_send(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, NULL,
-                          test_be_ptask_recv, NULL, "Test ptask", &ptask);
+                          test_be_ptask_recv, NULL, "Test ptask", 0, &ptask);
     assert_int_equal(ret, EINVAL);
     assert_null(ptask);
 }
@@ -348,7 +348,7 @@ void test_be_ptask_create_einval_recv(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          NULL, NULL, "Test ptask", &ptask);
+                          NULL, NULL, "Test ptask", 0, &ptask);
     assert_int_equal(ret, EINVAL);
     assert_null(ptask);
 }
@@ -362,7 +362,7 @@ void test_be_ptask_create_einval_name(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, NULL, NULL, &ptask);
+                          test_be_ptask_recv, NULL, NULL, 0, &ptask);
     assert_int_equal(ret, EINVAL);
     assert_null(ptask);
 }
@@ -378,7 +378,7 @@ void test_be_ptask_create_no_delay(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -406,7 +406,7 @@ void test_be_ptask_create_first_delay(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, DELAY, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -432,7 +432,7 @@ void test_be_ptask_disable(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -457,7 +457,7 @@ void test_be_ptask_enable(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -490,7 +490,7 @@ void test_be_ptask_enable_delay(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, DELAY, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -530,7 +530,7 @@ void test_be_ptask_offline_skip(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -565,7 +565,7 @@ void test_be_ptask_offline_disable(void **state)
                           BE_PTASK_OFFLINE_DISABLE,
                           BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -597,7 +597,7 @@ void test_be_ptask_offline_execute(void **state)
                           BE_PTASK_OFFLINE_EXECUTE,
                           BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -625,7 +625,7 @@ void test_be_ptask_reschedule_ok(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -657,7 +657,7 @@ void test_be_ptask_reschedule_null(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_null_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0,
                           &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
@@ -685,7 +685,7 @@ void test_be_ptask_reschedule_error(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_error_recv, test_ctx, "Test ptask",
+                          test_be_ptask_error_recv, test_ctx, "Test ptask", 0,
                           &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
@@ -713,7 +713,7 @@ void test_be_ptask_reschedule_timeout(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 1,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_timeout_send,
-                          test_be_ptask_error_recv, test_ctx, "Test ptask",
+                          test_be_ptask_error_recv, test_ctx, "Test ptask", 0,
                           &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
@@ -751,7 +751,7 @@ void test_be_ptask_reschedule_backoff(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           PERIOD*2, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -806,7 +806,7 @@ void test_be_ptask_get_period(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
 
@@ -827,7 +827,7 @@ void test_be_ptask_get_timeout(void **state)
     ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, TIMEOUT,
                           BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
                           0, test_be_ptask_send,
-                          test_be_ptask_recv, test_ctx, "Test ptask", &ptask);
+                          test_be_ptask_recv, test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
 
@@ -838,6 +838,24 @@ void test_be_ptask_get_timeout(void **state)
     assert_null(ptask);
 }
 
+void test_be_ptask_no_periodic(void **state)
+{
+    struct test_ctx *test_ctx = (struct test_ctx *)(*state);
+    struct be_ptask *ptask = NULL;
+    errno_t ret;
+
+    ret = be_ptask_create(test_ctx, test_ctx->be_ctx, 0, 0, DELAY, 0, 0,
+                          BE_PTASK_OFFLINE_SKIP, BE_PTASK_SCHEDULE_FROM_LAST,
+                          0, test_be_ptask_send,
+                          test_be_ptask_recv, test_ctx, "Test ptask",
+                          BE_PTASK_NO_PERIODIC, &ptask);
+    assert_int_equal(ret, ERR_OK);
+    assert_non_null(ptask);
+
+    be_ptask_destroy(&ptask);
+    assert_null(ptask);
+}
+
 void test_be_ptask_create_sync(void **state)
 {
     struct test_ctx *test_ctx = (struct test_ctx *)(*state);
@@ -848,7 +866,7 @@ void test_be_ptask_create_sync(void **state)
     now = get_current_time();
     ret = be_ptask_create_sync(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                                BE_PTASK_OFFLINE_SKIP, 0, test_be_ptask_sync,
-                               test_ctx, "Test ptask", &ptask);
+                               test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -876,7 +894,7 @@ void test_be_ptask_sync_reschedule_ok(void **state)
     now = get_current_time();
     ret = be_ptask_create_sync(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                                BE_PTASK_OFFLINE_SKIP, 0, test_be_ptask_sync,
-                               test_ctx, "Test ptask", &ptask);
+                               test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -908,7 +926,7 @@ void test_be_ptask_sync_reschedule_error(void **state)
     ret = be_ptask_create_sync(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                                BE_PTASK_OFFLINE_SKIP, 0,
                                test_be_ptask_sync_error,
-                               test_ctx, "Test ptask", &ptask);
+                               test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -938,7 +956,7 @@ void test_be_ptask_sync_reschedule_backoff(void **state)
     ret = be_ptask_create_sync(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
                                BE_PTASK_OFFLINE_SKIP, PERIOD*2,
                                test_be_ptask_sync_error,
-                               test_ctx, "Test ptask", &ptask);
+                               test_ctx, "Test ptask", 0, &ptask);
     assert_int_equal(ret, ERR_OK);
     assert_non_null(ptask);
     assert_non_null(ptask->timer);
@@ -1014,6 +1032,7 @@ int main(int argc, const char *argv[])
         new_test(be_ptask_reschedule_backoff),
         new_test(be_ptask_get_period),
         new_test(be_ptask_get_timeout),
+        new_test(be_ptask_no_periodic),
         new_test(be_ptask_create_sync),
         new_test(be_ptask_sync_reschedule_ok),
         new_test(be_ptask_sync_reschedule_error),
-- 
2.20.1