File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ const LOG_TAG = "core.Upload";
2323 */
2424export 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." ,
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments