diff options
author | priscilla <priscilla.huang@efrei.net> | 2023-02-07 09:17:52 -0500 |
---|---|---|
committer | priscilla <priscilla.huang@efrei.net> | 2023-02-07 09:19:13 -0500 |
commit | 345c3418b478cc04381898e98393df550ee563c6 (patch) | |
tree | 462148bb8503938e36e34520a0a893105f972d36 /src/backenddb | |
parent | 47f22f8001969bac389005d5e53e607e426e0ca2 (diff) | |
download | merchant-345c3418b478cc04381898e98393df550ee563c6.tar.gz merchant-345c3418b478cc04381898e98393df550ee563c6.tar.bz2 merchant-345c3418b478cc04381898e98393df550ee563c6.zip |
backenddb pending webhook test
Diffstat (limited to 'src/backenddb')
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 1 | ||||
-rw-r--r-- | src/backenddb/test_merchantdb.c | 140 |
2 files changed, 118 insertions, 23 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 5afe7f0a..ed43b3ed 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -7779,7 +7779,6 @@ postgres_update_pending_webhook (void *cls, params); } - /** * Delete a webhook in the pending webhook after the * webhook was completed successfully. diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index 6385147c..fea6c521 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -7806,11 +7806,6 @@ test_webhooks (void) */ struct PendingWebhookData { - /* - * webhook_pending_serial from SQL TABLE. - */ - uint64_t webhook_pending_serial; - /** * Reference to the configured webhook template. */ @@ -7885,16 +7880,98 @@ 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. next_attempt), "Update pending webhook failed\n"); return 0; } +/** + * 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 cls a pointer to the lookup closure. + * @param webhook_serial reference to the configured webhook template. + */ +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 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; +} + /** * Closure for testing pending webhook lookup @@ -7922,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 @@ -7942,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; + } + } } @@ -7975,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)) @@ -7990,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]) { @@ -8103,7 +8194,6 @@ test_lookup_all_webhooks (const struct InstanceData *instance, return 0; } - /** * Tests deleting a pending webhook. * @@ -8113,12 +8203,13 @@ test_lookup_all_webhooks (const struct InstanceData *instance, * @return 0 when successful, 1 otherwise. */ static int -test_delete_pending_webhook (uint64_t webhook_pending_serial, +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_pending_serial), + webhooks_pending_serial), "Delete webhook failed\n"); return 0; } @@ -8214,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, |