softonic / axios-retry

Axios plugin that intercepts failed requests and retries them whenever possible
Other
1.9k stars 167 forks source link

Doesn't timeout respects elapsed time due to exponentialDelay? #104

Open shaharsol opened 4 years ago

shaharsol commented 4 years ago

The following test doesn't pass. I'd expect the request to be aborted after 1000ms while axios-retry exponentially backs off, but it doesn't.

it('retries until fails due to timeout', async () => {
        nock('http://example.com')
            .put('/eventually-timeout')
            .times(4)
            .reply(503, 'service unavailable')
            .put('/eventually-timeout')
            .reply(201, {
                id: 2,
                name: 'John John Florence',
            });

        try {
            const client = axios.create();
            axiosRetry(client, {
                retries: 6,
                retryCondition: axiosRetry.isNetworkOrIdempotentRequestError,
                shouldResetTimeout: false,
                retryDelay: axiosRetry.exponentialDelay,
            });
            await client({
                method: 'put',
                url: 'http://example.com/eventually-timeout',
                timeout: 1000,
            });
            throw new Error('shouldnt be here');
        } catch (e) {
            expect(e.code).to.equal('ECONNABORTED');
        }
    });
"dependencies": {
    "axios": "^0.19.2",
    "axios-retry": "^3.1.2"
  }