sendhooks-engine
sendhooks-engine copied to clipboard
Write Unit Tests for the `queue` Package
The queue
package plays a vital role in our application, handling the queuing, retries, and exponential backoff logic for webhook deliveries. Comprehensive tests will ensure the reliability and robustness of this component.
Scope:
-
Test
ProcessWebhooks
:- Ensure that
sendWebhookWithRetries
is invoked for each payload in the webhookQueue. - Test with varying numbers of payloads.
- Ensure that
-
Test
sendWebhookWithRetries
:- Confirm that
retryWithExponentialBackoff
is correctly invoked. - Ensure logging takes place if a webhook fails after maximum retries.
- Confirm that
-
Test
calculateBackoff
:- Validate the calculation of backoff times.
- Confirm the doubling of backoff until it reaches
maxBackoff
.
-
Test
retryWithExponentialBackoff
:- Mock the behavior of
sender.SendWebhook
to simulate both successful sends and failures. - Confirm retries happen the expected number of times (
maxRetries
). - Ensure backoff time increases exponentially with each retry.
- Validate logging behavior at each retry and when maximum retries are reached.
- Mock the behavior of