[main][1ds] Enhance Retry Policy Testing for Alignment with Collector Policy (#2249)

* add test

* remove 204
This commit is contained in:
siyuniu-ms 2024-01-23 12:51:51 -08:00 коммит произвёл GitHub
Родитель a82c8e5c87
Коммит ef9ad261d6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 23 добавлений и 1 удалений

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

@ -23,7 +23,7 @@ const MaxBackoff = 600000;
export function retryPolicyShouldRetryForStatus(httpStatusCode: number): boolean {
/* tslint:disable:triple-equals */
// Disabling triple-equals rule to avoid httpOverrides from failing because they are returning a string value
return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 429)
|| (httpStatusCode == 501)
|| (httpStatusCode == 505));
/* tslint:enable:triple-equals */

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

@ -4,6 +4,7 @@ import { AppInsightsCore, BaseTelemetryPlugin, EventSendType, IAppInsightsCore,
import { PostChannel, IXHROverride, IPayloadData } from "../../../src/Index";
import { IPostTransmissionTelemetryItem, EventBatchNotificationReason, IChannelConfiguration } from "../../../src/DataModels";
import { EventBatch } from "../../../src/EventBatch";
import { retryPolicyShouldRetryForStatus } from "../../../src/RetryPolicy";
interface EventDetail {
batches: EventBatch[];
@ -2528,6 +2529,27 @@ export class HttpManagerTest extends AITestClass {
QUnit.assert.equal(fetchCalls.length, 2, "Make sure fetch was called");
}
});
this.testCase({
name: "HttpManager: RetryPolicy works as expected",
useFakeTimers: true,
test: () => {
// according to the one collector policy
// status that should retry : 429, 500, 503
// status that should not retry : 204 (will return complete before checking retry in httpManager), 400, 401, 403, 408, 415, 501, 505
QUnit.assert.equal(true, retryPolicyShouldRetryForStatus(429), "status code 429 should retry");
QUnit.assert.equal(true, retryPolicyShouldRetryForStatus(500), "status code 500 should retry");
QUnit.assert.equal(true, retryPolicyShouldRetryForStatus(503), "status code 503 should retry");
QUnit.assert.equal(false, retryPolicyShouldRetryForStatus(400), "status code 400 should not retry");
QUnit.assert.equal(false, retryPolicyShouldRetryForStatus(401), "status code 401 should not retry");
QUnit.assert.equal(false, retryPolicyShouldRetryForStatus(403), "status code 403 should not retry");
QUnit.assert.equal(false, retryPolicyShouldRetryForStatus(408), "status code 408 should not retry");
QUnit.assert.equal(false, retryPolicyShouldRetryForStatus(415), "status code 415 should not retry");
QUnit.assert.equal(false, retryPolicyShouldRetryForStatus(501), "status code 501 should not retry");
QUnit.assert.equal(false, retryPolicyShouldRetryForStatus(505), "status code 505 should not retry");
}
});
}
}