This commit is contained in:
Ladi Prosek 2019-05-29 14:44:50 +02:00
Родитель c09f2dd1d7
Коммит 27ef459736
2 изменённых файлов: 53 добавлений и 1 удалений

Просмотреть файл

@ -857,6 +857,7 @@ export class SimpleWebRequest<TBody, TOptions extends WebRequestOptions = WebReq
}
this._aborted = false;
this._timedOut = false;
this._finishHandled = false;
// Clear the XHR since we technically just haven't started again yet...

Просмотреть файл

@ -1,6 +1,6 @@
import * as faker from 'faker';
import * as SyncTasks from 'synctasks';
import { SimpleWebRequest, SimpleWebRequestOptions, WebErrorResponse, WebRequestPriority } from '../src/SimpleWebRequest';
import { ErrorHandlingType, SimpleWebRequest, SimpleWebRequestOptions, WebErrorResponse, WebRequestPriority } from '../src/SimpleWebRequest';
import { DETAILED_RESPONSE } from './helpers';
describe('SimpleWebRequest', () => {
@ -281,5 +281,56 @@ describe('SimpleWebRequest', () => {
});
});
describe('retries', () => {
beforeEach(() => {
jasmine.clock().install();
});
afterEach(() => {
jasmine.clock().uninstall();
});
it('fails the request with "timedOut: true" if it times out without retries', done => {
const url = faker.internet.url();
const method = 'GET';
new SimpleWebRequest<string>(url, method, { timeout: 10, customErrorHandler: () => ErrorHandlingType.DoNotRetry })
.start()
.then(() => {
expect(false).toBeTruthy();
done();
})
.catch(errResp => {
expect(errResp.timedOut).toBeTruthy();
done();
}
);
jasmine.clock().tick(10);
});
it('timedOut flag is reset on retry', done => {
const url = faker.internet.url();
const method = 'GET';
const requestPromise = new SimpleWebRequest<string>(url, method, {
timeout: 10,
retries: 1,
customErrorHandler: () => ErrorHandlingType.RetryCountedWithBackoff
}).start();
requestPromise.then(() => {
expect(false).toBeTruthy();
done();
})
.catch(errResp => {
expect(errResp.canceled).toBeTruthy();
expect(errResp.timedOut).toBeFalsy();
done();
});
// first try will time out, the second one will be aborted
jasmine.clock().tick(10);
requestPromise.cancel();
});
});
// @TODO Add more unit tests
});