mocha icon indicating copy to clipboard operation
mocha copied to clipboard

🚀 Feature: Retry logic should accommodate a timeout between retries

Open enigmatic00 opened this issue 8 years ago • 5 comments

this.retries(N); should support a timeout value before attempting to run the test again.

A signature like this.retries(N[, M]); where N is the # of retries & M is the # of ms to wait before trying the test again would be ideal

enigmatic00 avatar May 18 '16 18:05 enigmatic00

This would be great for my end-to-end tests

aaclarker avatar Sep 21 '16 18:09 aaclarker

yes this will be really helpful. Waiting for this to be implemented :)

sunilaadike avatar Feb 23 '17 10:02 sunilaadike

I was able to use beforeEach to delay test execution in case of retries - in the following example we need to back off proportionally to the number of failures, but it can easily be a constant

describe(....

    // delay after first failure
    beforeEach(function(done){
      if(this.currentTest.currentRetry() > 0){
         setTimeout(done, this.currentTest.currentRetry() * 500);
      } else {
         done();
      }
   })
   this.retries(2)
  ...
  // test cases here 
  it( .... 

ledbit avatar Jan 06 '18 07:01 ledbit

This seems reasonable to me. I think we'd probably want to make the second parameter to retries an optional object that may contain a property like wait. Two benefits:

  • It'll be more clear what this new number is doing
  • If more settings get requested in the future, we don't have to have two allowed types for the second parameter

cc @mochajs/maintenance-crew

JoshuaKGoldberg avatar Feb 06 '24 03:02 JoshuaKGoldberg

Chatted with @voxpelli: this seems reasonable and straightforward to implement, and we don't think this will open too many rabbit holes. 🤞

JoshuaKGoldberg avatar Feb 27 '24 16:02 JoshuaKGoldberg