Skip to content

Commit

Permalink
Add 500 retry codes and associated unit tests. (microsoft#1003)
Browse files Browse the repository at this point in the history
Co-authored-by: Jackson Weber <jacksonweber@microsoft.com>
  • Loading branch information
JacksonWeber and JacksonWeber authored Aug 18, 2022
1 parent 34208e4 commit e0d2ad4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Library/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ class Sender {
statusCode === 408 || // Timeout
statusCode === 429 || // Too many requests
statusCode === 500 || // Server Error
statusCode === 503 // Server Unavailable
statusCode === 502 || // Bad Gateway
statusCode === 503 || // Server Unavailable
statusCode === 504 // Gateway Timeout
);
}

Expand Down
50 changes: 49 additions & 1 deletion Tests/Library/Sender.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("Library/Sender", () => {
});
});

it("should put telemetry in disk when retryable code is returned", (done) => {
it("should put telemetry in disk when retryable 408 code is returned", (done) => {
var envelope = new Contracts.Envelope();
envelope.name = "TestRetryable";
nockScope = interceptor.reply(408, null);
Expand All @@ -113,6 +113,54 @@ describe("Library/Sender", () => {
});
});

it("should put telemetry in disk when retryable 500 code is returned", (done) => {
var envelope = new Contracts.Envelope();
envelope.name = "TestRetryable";
nockScope = interceptor.reply(500, null);
var storeStub = sandbox.stub(sender, "_storeToDisk");
sender.send([envelope], (responseText) => {
assert.ok(storeStub.calledOnce);
assert.equal(storeStub.firstCall.args[0][0].name, "TestRetryable");
done();
});
});

it("should put telemetry in disk when retryable 502 code is returned", (done) => {
var envelope = new Contracts.Envelope();
envelope.name = "TestRetryable";
nockScope = interceptor.reply(502, null);
var storeStub = sandbox.stub(sender, "_storeToDisk");
sender.send([envelope], (responseText) => {
assert.ok(storeStub.calledOnce);
assert.equal(storeStub.firstCall.args[0][0].name, "TestRetryable");
done();
});
});

it("should put telemetry in disk when retryable 503 code is returned", (done) => {
var envelope = new Contracts.Envelope();
envelope.name = "TestRetryable";
nockScope = interceptor.reply(503, null);
var storeStub = sandbox.stub(sender, "_storeToDisk");
sender.send([envelope], (responseText) => {
assert.ok(storeStub.calledOnce);
assert.equal(storeStub.firstCall.args[0][0].name, "TestRetryable");
done();
});
});

it("should put telemetry in disk when retryable 504 code is returned", (done) => {
var envelope = new Contracts.Envelope();
envelope.name = "TestRetryable";
nockScope = interceptor.reply(504, null);
var storeStub = sandbox.stub(sender, "_storeToDisk");
sender.send([envelope], (responseText) => {
assert.ok(storeStub.calledOnce);
assert.equal(storeStub.firstCall.args[0][0].name, "TestRetryable");
done();
});
});

it("should retry only failed events in partial content response", (done) => {
var breezeResponse: Contracts.BreezeResponse = {
itemsAccepted: 2,
Expand Down

0 comments on commit e0d2ad4

Please sign in to comment.