@@ -376,3 +376,47 @@ func TestFeedScheduleNextCheckEntryFrequencyLargeNewTTL(t *testing.T) {
376376 t .Error (`The next_check_at should be after timeBefore + entry frequency min interval` )
377377 }
378378}
379+
380+ func TestFeedScheduleNextCheckParsingErrorsBackoff (t * testing.T ) {
381+ for count := range 10 {
382+ f1 := & Feed {ParsingErrorCount : 0 }
383+ f2 := & Feed {ParsingErrorCount : count }
384+ newTTL := time .Duration (1 ) * time .Minute * 2
385+ f1 .ScheduleNextCheck (0 , newTTL )
386+ f2 .ScheduleNextCheck (0 , newTTL )
387+
388+ if f1 .NextCheckAt .IsZero () {
389+ t .Error (`The next_check_at for f1 must be set` )
390+ }
391+ if f2 .NextCheckAt .IsZero () {
392+ t .Error (`The next_check_at for f2 must be set` )
393+ }
394+
395+ if f1 .NextCheckAt .Add (backoff (count )).Sub (f2 .NextCheckAt ).Minutes () > 10 {
396+ t .Error ("The next_check_at should have been using the exponential backoff." )
397+ }
398+ }
399+ }
400+
401+ func TestFeedScheduleNextCheckParsingErrorsBackoffMax (t * testing.T ) {
402+ f1 := & Feed {ParsingErrorCount : 0 }
403+ newTTL := time .Duration (1 ) * time .Minute * 2
404+ f1 .ScheduleNextCheck (0 , newTTL )
405+ if f1 .NextCheckAt .IsZero () {
406+ t .Error (`The next_check_at for f1 must be set` )
407+ }
408+
409+ for count := range 128 {
410+ f2 := & Feed {ParsingErrorCount : count }
411+ f2 .ScheduleNextCheck (0 , newTTL )
412+
413+ if f2 .NextCheckAt .IsZero () {
414+ t .Error (`The next_check_at for f1 must be set` )
415+ }
416+
417+ offset := f2 .NextCheckAt .Sub (f1 .NextCheckAt )
418+ if offset > backoffMax + time .Minute * 1 {
419+ t .Errorf ("The next_check_at's offset for errors (%q) for %d errors should never be bigger than %q." , offset , count , backoffMax )
420+ }
421+ }
422+ }
0 commit comments