tim-kos/node-retry

Setting maxTimeout to undefined breaks minTimeout behavior

vilaemail opened this issue · 0 comments

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