Skip to content

Commit 74d05e2

Browse files
committed
Move maxRecoverableFailures to Policy class
1 parent b605cf5 commit 74d05e2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

glean/src/core/upload/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const LOG_TAG = "core.Upload";
2323
*/
2424
export class Policy {
2525
constructor (
26+
// The maximum recoverable failures allowed per uploading window.
27+
//
28+
// Limiting this is necessary to avoid infinite loops on requesting upload tasks.
29+
readonly maxRecoverableFailures: number = 3,
2630
// The maximum size in bytes a ping body may have to be eligible for upload.
2731
readonly maxPingBodySize: number = 1024 * 1024 // 1MB
2832
) {}
@@ -289,7 +293,7 @@ class PingUploader implements PingsDatabaseObserver {
289293
this.enqueuePing(nextPing);
290294
}
291295

292-
if (retries >= 3) {
296+
if (retries >= this.policy.maxRecoverableFailures) {
293297
log(
294298
LOG_TAG,
295299
"Reached maximum recoverable failures for the current uploading window. You are done.",

glean/tests/unit/core/upload/index.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,23 @@ describe("PingUploader", function() {
195195
status: 500,
196196
result: UploadResultStatus.Success
197197
}));
198+
199+
// Create a new ping uploader with a fixed max recoverable failures limit.
200+
const uploader = new PingUploader(
201+
new Configuration(),
202+
Glean.platform,
203+
Context.pingsDatabase,
204+
new Policy(
205+
3, // maxRecoverableFailures
206+
)
207+
);
208+
209+
// Overwrite the Glean ping uploader with the test one.
210+
Context.pingsDatabase.attachObserver(uploader);
211+
198212
await fillUpPingsDatabase(1);
213+
await waitForUploader(uploader);
199214

200-
await waitForUploader();
201215
assert.strictEqual(stub.callCount, 3);
202216
});
203217

0 commit comments

Comments
 (0)