pactum icon indicating copy to clipboard operation
pactum copied to clipboard

Add proper logging for retry mechanism

Open Rajaneeshkumar opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe. I employed a retry mechanism for my tests, but determining whether the tests were actually retried upon failure was challenging because no related messages were printed in the console/terminal. After going through tosser.js and conducting some debugging, I discovered that retries were indeed occurring.

Describe the solution you'd like In the setResponse() method located in tosser.js, it would be beneficial to include log statements indicating the number of retry attempts within the specified block.

 if (!noRetry) {
          const scale = delay === 1000 ? 'second' : 'seconds';
          log.debug(`Retrying request in ${delay / 1000} ${scale}`);
          await helper.sleep(delay);
          this.response = await getResponse(this);
        }

Additional context As a user, having detailed logging output to the terminal would greatly facilitate debugging issues. I would appreciate a prompt response from you on this matter. @ASaiAnudeep

Rajaneeshkumar avatar Feb 20 '24 07:02 Rajaneeshkumar

@Rajaneeshkumar please help raise a PR with the suggested changes.

ASaiAnudeep avatar Feb 20 '24 09:02 ASaiAnudeep

Hi @ASaiAnudeep , Raised PR https://github.com/pactumjs/pactum/pull/315 for this changes Please review

Rajaneeshkumar avatar Feb 20 '24 10:02 Rajaneeshkumar

@Rajaneeshkumar depending on the retry count, the requested change might spam the console output. Instead of changing it into info log just for this usecase, have you tried setting the log level to debug? https://pactumjs.github.io/api/settings/setLogLevel.html#setloglevel

leelaprasadv avatar Feb 20 '24 11:02 leelaprasadv

@leelaprasadv I have tried to set the log level to debug to gain more insight into the process. However, this action resulted in a spamming of debug logs from various sources being printed to the console. I want to apply retry logic to all requests in the project globally, not for specific requests. Could you please suggest any other workaround?

Rajaneeshkumar avatar Feb 20 '24 12:02 Rajaneeshkumar

@ASaiAnudeep / @leelaprasadv Could you please provide an update on the status of the above request?

Rajaneeshkumar avatar Feb 27 '24 05:02 Rajaneeshkumar

closed in https://github.com/pactumjs/pactum/pull/315

ASaiAnudeep avatar Feb 27 '24 13:02 ASaiAnudeep