tim-kos / node-retry

Abstraction for exponential and custom retry strategies for failed operations.
Other
1.22k stars 80 forks source link

Setting maxTimeout to undefined breaks minTimeout behavior #90

Open vilaemail opened 1 year ago

vilaemail commented 1 year ago

Repro code:

const retry = require('retry');

const testCase = (configAmmend) => {
    return new Promise((resolve) => {
        const op = retry.operation({
            retries: 1,
            minTimeout: 800,
            factor: 1,
            ...configAmmend
        });

        const startTime = Date.now();
        op.attempt((attempt) => {
            console.log(`${attempt}: ${Date.now() - startTime}`);
            op.retry(new Error('fail on purpose'));
            if (attempt === 2) {
                resolve();
            }
        });
    });
};

const test = async () => {
    console.log('test 1');
    await testCase({});
    console.log('test 2');
    await testCase({ maxTimeout: 1000 });
    console.log('test 3');
    await testCase({ maxTimeout: undefined });
}

test();

Expected behavior:

test 1
1: 0
2: 809
test 2
1: 0
2: 810
test 3
1: 0
2: 809

Actual behavior:

test 1
1: 0
2: 809
test 2
1: 0
2: 810
test 3
1: 0
2: 15