Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion channels/1ds-post-js/src/RetryPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
22 changes: 22 additions & 0 deletions channels/1ds-post-js/test/Unit/src/HttpManagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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");
}
});

}
}

Expand Down
Loading