I have built an azure function using NodeJs. And I am Using Jest for testing.
Scenario: When making API calls from function, if the 3rd party returns Timeout, I need to retry 1 more time and then quit. This is working fine when live and server is retrying automatically as expected.
I am failing to write test cases as getting an Jest Timeout error.
Logic:
function.json
"retry": {
"strategy": "exponentialBackoff",
"maxRetryCount": 1,
"minimumInterval": "00:00:10",
"maximumInterval": "00:00:40"
}
index.js - under try/catch
catch (err) {
let errorCode = err.errorCode || err.code || 500;
let errorMessage = err.message|| err.errorMessage;
if (errorMessage && errorMessage.indexOf("ETIMEDOUT") >= 0 ) {
errorCode = 429; //setting errorCode as 429 to retry automatically from azure function
let retryError = new Error("retrying requests");
retryError.code = 429;
throw retryError;
}else{
context.done();
}
};
index.test.js
Test suite failed to run retrying requests
The test class breaks at this line "let retryError = new Error("retrying requests");" once the error is thrown from main class.
So, if the server retry exhausted and still the response is 429, how to write test cases?