gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] branch master updated (567702d2 -> 95d71206)


From: gnunet
Subject: [taler-merchant] branch master updated (567702d2 -> 95d71206)
Date: Tue, 07 Feb 2023 15:19:22 +0100

This is an automated email from the git hooks/post-receive script.

priscilla-huang pushed a change to branch master
in repository merchant.

    from 567702d2 -check for curl
     new 47f22f80 git pull
     new 345c3418 backenddb pending webhook test
     new 95d71206 backenddb pending webhook test

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backenddb/plugin_merchantdb_postgres.c |  83 ------------
 src/backenddb/test_merchantdb.c            | 204 ++++++++++++++++-------------
 src/include/taler_merchantdb_plugin.h      |  20 +--
 3 files changed, 117 insertions(+), 190 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index e91766be..ed43b3ed 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -7534,73 +7534,6 @@ postgres_insert_pending_webhook (void *cls,
 }
 
 
-/**
- * Lookup details about a particular pending webhook.
- *
- * @param cls closure
- * @param instance_id instance to lookup webhook for
- * @param webhook_serial webhook to lookup
- * @param[out] pwb set to the pending webhook details on success, can be NULL
- *             (in that case we only want to check if the webhook exists)
- * @return database result code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_pending_webhook (void *cls,
-                                 const char *instance_id,
-                                 uint64_t *webhook_serial,
-                                 struct TALER_MERCHANTDB_PendingWebhookDetails 
*
-                                 pwb)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_uint64 (webhook_serial),
-    GNUNET_PQ_query_param_end
-  };
-
-  if (NULL == pwb)
-  {
-    struct GNUNET_PQ_ResultSpec rs_null[] = {
-      GNUNET_PQ_result_spec_end
-    };
-
-    check_connection (pg);
-    return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                     "lookup_pending_webhook",
-                                                     params,
-                                                     rs_null);
-  }
-  else
-  {
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_absolute_time ("next_attempt",
-                                           &pwb->next_attempt),
-      GNUNET_PQ_result_spec_uint32 ("retries",
-                                    &pwb->retries),
-      GNUNET_PQ_result_spec_string ("url",
-                                    &pwb->url),
-      GNUNET_PQ_result_spec_string ("http_method",
-                                    &pwb->http_method),
-      GNUNET_PQ_result_spec_allow_null (
-        GNUNET_PQ_result_spec_string ("header",
-                                      &pwb->header),
-        NULL),
-      GNUNET_PQ_result_spec_allow_null (
-        GNUNET_PQ_result_spec_string ("body",
-                                      &pwb->body),
-        NULL),
-      GNUNET_PQ_result_spec_end
-    };
-
-    check_connection (pg);
-    return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                     "lookup_pending_webhook",
-                                                     params,
-                                                     rs);
-  }
-}
-
-
 /**
  * Context used for postgres_lookup_future_webhook().
  */
@@ -7846,7 +7779,6 @@ postgres_update_pending_webhook (void *cls,
                                              params);
 }
 
-
 /**
  * Delete a webhook in the pending webhook after the
  * webhook was completed successfully.
@@ -10469,20 +10401,6 @@ postgres_connect (void *cls)
                             " retries=retries+1"
                             ",next_attempt=$2"
                             " WHERE webhook_pending_serial=$1"),
-    /* for postgres_lookup_pending_webhook(): DELETE? Seems useless... */
-    GNUNET_PQ_make_prepare ("lookup_pending_webhook",
-                            "SELECT"
-                            " next_attempt"
-                            ",retries"
-                            ",url"
-                            ",http_method"
-                            ",header"
-                            ",body"
-                            " FROM merchant_pending_webhooks"
-                            " JOIN merchant_instances"
-                            "   USING (merchant_serial)"
-                            " WHERE merchant_instances.merchant_id=$1"
-                            "   AND 
merchant_pending_webhooks.webhook_serial=$2"),
     /* for postgres_lookup_pending_webhooks() */
     GNUNET_PQ_make_prepare ("lookup_pending_webhooks",
                             "SELECT"
@@ -10686,7 +10604,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
   plugin->delete_webhook = &postgres_delete_webhook;
   plugin->insert_webhook = &postgres_insert_webhook;
   plugin->update_webhook = &postgres_update_webhook;
-  plugin->lookup_pending_webhook = &postgres_lookup_pending_webhook;
   plugin->lookup_webhook_by_event = &postgres_lookup_webhook_by_event;
   plugin->lookup_all_webhooks = &postgres_lookup_all_webhooks;
   plugin->lookup_future_webhook = &postgres_lookup_future_webhook;
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index e986d8f7..fea6c521 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -7838,39 +7838,6 @@ make_pending_webhook (uint64_t webhook_serial,
 }
 
 
-/**
- * Compare two pending webhooks for equality.
- *
- * @param a the first pending webhook.
- * @param b the second pending webhook.
- * @return 0 on equality, 1 otherwise.
- */
-static int
-check_pending_webhooks_equal (const struct
-                              TALER_MERCHANTDB_PendingWebhookDetails *a,
-                              const struct
-                              TALER_MERCHANTDB_PendingWebhookDetails *b)
-{
-  if (GNUNET_TIME_absolute_cmp (a->next_attempt,
-                                !=,
-                                b->next_attempt) ||
-      (a->retries != b->retries) ||
-      (0 != strcmp (a->url,
-                    b->url)) ||
-      (0 != strcmp (a->http_method,
-                    b->http_method)) ||
-      (0 != strcmp (a->header,
-                    b->header)) ||
-      (0 != strcmp (a->body,
-                    b->body)))
-  {
-    fprintf (stdout, " retries %d vs %d", a->retries, b->retries);
-    return 1;
-  }
-  return 0;
-}
-
-
 /**
  * Tests inserting pending webhook data into the database.
  *
@@ -7888,8 +7855,7 @@ test_insert_pending_webhook (const struct InstanceData 
*instance,
   TEST_COND_RET_ON_FAIL (expected_result ==
                          plugin->insert_pending_webhook (plugin->cls,
                                                          instance->instance.id,
-                                                         pwebhook->
-                                                         webhook_serial,
+                                                         
pwebhook->webhook_serial,
                                                          
pwebhook->pwebhook.url,
                                                          pwebhook->pwebhook.
                                                          http_method,
@@ -7914,11 +7880,11 @@ test_update_pending_webhook (const struct InstanceData 
*instance,
                              struct PendingWebhookData *pwebhook,
                              enum GNUNET_DB_QueryStatus expected_result)
 {
+  struct GNUNET_TIME_Absolute next_attempt; // FIXME: uninitialized!
+
   TEST_COND_RET_ON_FAIL (expected_result ==
                          plugin->update_pending_webhook (plugin->cls,
-                                                         pwebhook->
-                                                         webhook_serial,
-                                                         pwebhook->pwebhook.
+                                                         
pwebhook->webhook_serial,
                                                          next_attempt),
                          "Update pending webhook failed\n");
   return 0;
@@ -7926,40 +7892,84 @@ test_update_pending_webhook (const struct InstanceData 
*instance,
 
 
 /**
- * Tests looking up a pending webhook from the db.
+ * Container for information for looking up the row number of a deposit.
+ */
+struct LookupPendingWebhookSerial_Closure
+{
+  /**
+   * The pending webhook we're looking for.
+   */
+  const struct PendingWebhookData *pwebhook;
+
+  /**
+   * The serial found.
+   */
+  uint64_t webhook_pending_serial;
+};
+
+
+/**
+ * Function called after calling @e test_lookup_all_webhook,
+ * test_lookup_future_webhook and test_lookup_pending_webhook
  *
- * @param instance the instance to query from.
- * @param pwebhook the pending webhook to query and compare to.
- * @return 0 when successful, 1 otherwise.
+ * @param cls a pointer to the lookup closure.
+ * @param webhook_serial reference to the configured webhook template.
  */
-static int
-test_lookup_pending_webhook (const struct InstanceData *instance,
-                             struct PendingWebhookData *pwebhook)
+static void
+get_pending_serial_cb (void *cls,
+                       uint64_t webhook_pending_serial,
+                       struct GNUNET_TIME_Absolute next_attempt,
+                       uint32_t retries,
+                       const char *url,
+                       const char *http_method,
+                       const char *header,
+                       const char *body)
+{
+  struct LookupPendingWebhookSerial_Closure *lpw = cls;
+  if (NULL == lpw)
+    return;
+  if ((GNUNET_TIME_absolute_cmp (
+                                 lpw->pwebhook->pwebhook.next_attempt,
+                                 ==,
+                                 next_attempt)) &&
+      (lpw->pwebhook->pwebhook.retries == retries) &&
+      (0 == strcmp (lpw->pwebhook->pwebhook.url,
+                    url)) &&
+      (0 == strcmp (lpw->pwebhook->pwebhook.http_method,
+                    http_method)) &&
+      (0 == strcmp (lpw->pwebhook->pwebhook.header,
+                    header)) &&
+      (0 == strcmp (lpw->pwebhook->pwebhook.body,
+                    body)) )
+    {
+      lpw->webhook_pending_serial = webhook_pending_serial;
+    }
+}
+
+
+/**
+ * Convenience function to retrieve the row number of a webhook pending in the 
database.
+ *
+ * @param instance the instance to get webhook pending(wp) from.
+ * @param webhook pending the wp to lookup the serial for.
+ * @return the row number of the deposit.
+ */
+static uint64_t
+get_pending_serial (const struct InstanceData *instance,
+                    const struct PendingWebhookData *pwebhook)
 {
-  struct TALER_MERCHANTDB_PendingWebhookDetails lookup_result;
-  if (0 > plugin->lookup_pending_webhook (plugin->cls,
-                                          instance->instance.id,
-                                          &pwebhook->webhook_serial,
-                                          &lookup_result))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Lookup pending webhook failed\n");
-    TALER_MERCHANTDB_pending_webhook_details_free (&lookup_result);
-    return 1;
-  }
-  const struct TALER_MERCHANTDB_PendingWebhookDetails *to_cmp =
-    &pwebhook->pwebhook;
-  if (0 != check_pending_webhooks_equal (&lookup_result,
-                                         to_cmp))
-  {
-    GNUNET_break (0);
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Lookup pending webhook failed: incorrect pending webhook 
returned\n");
-    TALER_MERCHANTDB_pending_webhook_details_free (&lookup_result);
-    return 1;
-  }
-  TALER_MERCHANTDB_pending_webhook_details_free (&lookup_result);
-  return 0;
+  struct LookupPendingWebhookSerial_Closure lpw = {
+    .pwebhook = pwebhook,
+    .webhook_pending_serial = 0
+  };
+
+  GNUNET_assert (0 <
+                 plugin->lookup_future_webhook (plugin->cls,
+                                                &get_pending_serial_cb,
+                                                &lpw));
+  GNUNET_assert (0 != lpw.webhook_pending_serial);
+
+  return lpw.webhook_pending_serial;
 }
 
 
@@ -7989,6 +7999,7 @@ struct TestLookupPendingWebhooks_Closure
   unsigned int results_length;
 };
 
+
 /**
  * Function called after calling @e test_lookup_all_webhook,
  * test_lookup_future_webhook and test_lookup_pending_webhook
@@ -8009,15 +8020,27 @@ lookup_pending_webhooks_cb (void *cls,
   struct TestLookupPendingWebhooks_Closure *cmp = cls;
   if (NULL == cmp)
     return;
-  cmp->results_length += 1;
+  cmp->results_length++;
   for (unsigned int i = 0; cmp->webhooks_to_cmp_length > i; ++i)
   {
-    if ((cmp->webhooks_to_cmp[i].webhook_serial != webhook_serial) &&
+    if ((cmp->webhooks_to_cmp[i].webhook_serial == webhook_serial) &&
         (GNUNET_TIME_absolute_cmp (
            cmp->webhooks_to_cmp[i].pwebhook.next_attempt,
-           !=,
-           next_attempt)))
-      cmp->results_matching[i] += 1;
+           ==,
+           next_attempt)) &&
+        (cmp->webhooks_to_cmp[i].pwebhook.retries == retries) &&
+        (0 == strcmp (cmp->webhooks_to_cmp[i].pwebhook.url,
+                      url)) &&
+        (0 == strcmp (cmp->webhooks_to_cmp[i].pwebhook.http_method,
+                      http_method)) &&
+        (0 == strcmp (cmp->webhooks_to_cmp[i].pwebhook.header,
+                      header)) &&
+        (0 == strcmp (cmp->webhooks_to_cmp[i].pwebhook.body,
+                      body)) )
+      {
+        cmp->results_matching[i] += 1;
+      }
+    
   }
 }
 
@@ -8042,7 +8065,8 @@ test_lookup_pending_webhooks (const struct InstanceData 
*instance,
     .results_matching = results_matching,
     .results_length = 0
   };
-  memset (results_matching, 0, sizeof (unsigned int) * pwebhooks_length);
+  
+  memset (results_matching, 0, sizeof (results_matching));
   if (0 > plugin->lookup_pending_webhooks (plugin->cls,
                                            &lookup_pending_webhooks_cb,
                                            &cls))
@@ -8057,7 +8081,7 @@ test_lookup_pending_webhooks (const struct InstanceData 
*instance,
                 "Lookup pending webhook failed: incorrect number of 
results\n");
     return 1;
   }
-  for (unsigned int i = 0; pwebhooks_length > i; ++i)
+  for (unsigned int i = 0; i < pwebhooks_length; i++)
   {
     if (1 != cls.results_matching[i])
     {
@@ -8170,7 +8194,6 @@ test_lookup_all_webhooks (const struct InstanceData 
*instance,
   return 0;
 }
 
-
 /**
  * Tests deleting a pending webhook.
  *
@@ -8180,12 +8203,13 @@ test_lookup_all_webhooks (const struct InstanceData 
*instance,
  * @return 0 when successful, 1 otherwise.
  */
 static int
-test_delete_pending_webhook (const struct PendingWebhookData *webhook,
+test_delete_pending_webhook (uint64_t webhooks_pending_serial,
                              enum GNUNET_DB_QueryStatus expected_result)
 {
+
   TEST_COND_RET_ON_FAIL (expected_result ==
                          plugin->delete_pending_webhook (plugin->cls,
-                                                         
webhook->webhook_serial),
+                                                         
webhooks_pending_serial),
                          "Delete webhook failed\n");
   return 0;
 }
@@ -8267,9 +8291,6 @@ run_test_pending_webhooks (struct 
TestPendingWebhooks_Closure *cls)
   TEST_RET_ON_FAIL (test_insert_pending_webhook (&cls->instance,
                                                  &cls->pwebhooks[0],
                                                  
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-  /* Test lookup of individual pending webhook */
-  TEST_RET_ON_FAIL (test_lookup_pending_webhook (&cls->instance,
-                                                 &cls->pwebhooks[0]));
   /* Test pending webhook update */
   cls->pwebhooks[0].pwebhook.next_attempt = GNUNET_TIME_absolute_get ();
 
@@ -8284,23 +8305,28 @@ run_test_pending_webhooks (struct 
TestPendingWebhooks_Closure *cls)
   TEST_RET_ON_FAIL (test_insert_pending_webhook (&cls->instance,
                                                  &cls->pwebhooks[1],
                                                  
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-  TEST_RET_ON_FAIL (test_lookup_future_webhook (&cls->instance,
-                                                1,
-                                                cls->pwebhooks));
   TEST_RET_ON_FAIL (test_lookup_pending_webhooks (&cls->instance,
                                                   2,
                                                   cls->pwebhooks));
   TEST_RET_ON_FAIL (test_lookup_all_webhooks (&cls->instance,
                                               2,
                                               cls->pwebhooks));
+  TEST_RET_ON_FAIL (test_lookup_future_webhook (&cls->instance,
+                                                1,
+                                                cls->pwebhooks));
+
+  uint64_t webhook_pending_serial0 = get_pending_serial (&cls->instance,
+                                                         &cls->pwebhooks[0]);
+  uint64_t webhook_pending_serial1 = get_pending_serial (&cls->instance,
+                                                         &cls->pwebhooks[1]);
 
   /* Test webhook deletion */
-  TEST_RET_ON_FAIL (test_delete_pending_webhook (&cls->pwebhooks[1],
+  TEST_RET_ON_FAIL (test_delete_pending_webhook (webhook_pending_serial1,
                                                  
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
   /* Test double deletion fails */
-  TEST_RET_ON_FAIL (test_delete_pending_webhook (&cls->pwebhooks[1],
+  TEST_RET_ON_FAIL (test_delete_pending_webhook (webhook_pending_serial1,
                                                  
GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
-  TEST_RET_ON_FAIL (test_delete_pending_webhook (&cls->pwebhooks[0],
+  TEST_RET_ON_FAIL (test_delete_pending_webhook (webhook_pending_serial0,
                                                  
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
   TEST_RET_ON_FAIL (test_lookup_all_webhooks (&cls->instance,
                                               0,
@@ -8344,7 +8370,7 @@ run_tests (void)
   TEST_RET_ON_FAIL (test_kyc ());
   TEST_RET_ON_FAIL (test_templates ());
   TEST_RET_ON_FAIL (test_webhooks ());
-  // TEST_RET_ON_FAIL (test_pending_webhooks ());
+  TEST_RET_ON_FAIL (test_pending_webhooks ());
   return 0;
 }
 
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 9b9d1505..a1208859 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -420,8 +420,7 @@ typedef void
 typedef void
 (*TALER_MERCHANTDB_PendingWebhooksCallback)(void *cls,
                                             uint64_t webhook_pending_serial,
-                                            struct GNUNET_TIME_Absolute
-                                            next_attempt,
+                                            struct GNUNET_TIME_Absolute 
next_attempt,
                                             uint32_t retries,
                                             const char *url,
                                             const char *http_method,
@@ -434,6 +433,7 @@ typedef void
  */
 struct TALER_MERCHANTDB_PendingWebhookDetails
 {
+
   /**
    * Identifies when we should make the next request to the webhook. 0 for 
unknown,
    * #GNUNET_TIME_UNIT_FOREVER_ABS for never.
@@ -2752,22 +2752,6 @@ struct TALER_MERCHANTDB_Plugin
                             const char *http_method,
                             const char *header,
                             const char *body);
-
-  /**
-   * Lookup details about a particular pending webhook.
-   *
-   * @param cls closure
-   * @param instance_id instance to lookup webhook for
-   * @param webhook_serial webhook to lookup
-   * @param[out] pwb set to the pending webhook details on success, can be NULL
-   *             (in that case we only want to check if the webhook exists)
-   * @return database result code
-   */
-  enum GNUNET_DB_QueryStatus
-  (*lookup_pending_webhook)(void *cls,
-                            const char *instance_id,
-                            uint64_t *webhook_serial,
-                            struct TALER_MERCHANTDB_PendingWebhookDetails 
*pwb);
   /**
    * Lookup the webhook that need to be send in priority. These webhooks are 
not successfully
    * send.

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]