@@ -430,6 +430,7 @@ void main() {
430
430
431
431
void checkRetry (String description, void Function () prepareError, {
432
432
String ? errorMessage,
433
+ int failureCountNofityThreshold = 0 ,
433
434
}) {
434
435
test (description, () {
435
436
awaitFakeAsync ((async ) async {
@@ -438,18 +439,26 @@ void main() {
438
439
updateMachine.poll ();
439
440
check (async .pendingTimers).length.equals (0 );
440
441
441
- // Make the request, inducing an error in it.
442
- prepareError ();
443
- updateMachine.debugAdvanceLoop ();
444
- check (debugLastReportedError).isNull ();
445
- async .elapse (Duration .zero);
446
- if (errorMessage == null ) {
447
- check (takeLastReportedError ()).isNull ();
448
- } else {
449
- check (takeLastReportedError ()).isNotNull ().contains (errorMessage);
442
+ for (int i = 0 ; i < failureCountNofityThreshold + 1 ; i++ ) {
443
+ // Make the request, inducing an error in it.
444
+ prepareError ();
445
+ if (i > 0 ) {
446
+ // End polling backoff from the previous iteration.
447
+ async .flushTimers ();
448
+ }
449
+ updateMachine.debugAdvanceLoop ();
450
+ check (debugLastReportedError).isNull ();
451
+ async .elapse (Duration .zero);
452
+ if (i < failureCountNofityThreshold || errorMessage == null ) {
453
+ check (debugTakeLastReportedError ()).isNull ();
454
+ } else {
455
+ final error = debugTakeLastReportedError ();
456
+ print (error);
457
+ check (error).isNotNull ().contains (errorMessage);
458
+ }
459
+ checkLastRequest (lastEventId: 1 );
460
+ check (store).isLoading.isTrue ();
450
461
}
451
- checkLastRequest (lastEventId: 1 );
452
- check (store).isLoading.isTrue ();
453
462
454
463
// Polling doesn't resume immediately; there's a timer.
455
464
check (async .pendingTimers).length.equals (1 );
@@ -471,11 +480,15 @@ void main() {
471
480
}
472
481
473
482
group ('retries' , () {
474
- checkRetry ('retries on Server5xxException' ,
475
- () => connection.prepare (httpStatus: 500 , body: 'splat' ));
476
-
477
- checkRetry ('retries on NetworkException' ,
478
- () => connection.prepare (exception: Exception ("failed" )));
483
+ checkRetry ('too many retries on Server5xxException' ,
484
+ () => connection.prepare (httpStatus: 500 , body: 'splat' ),
485
+ errorMessage: 'Failed to reach server. Will retry' ,
486
+ failureCountNofityThreshold: 5 );
487
+
488
+ checkRetry ('too many retries on NetworkException' ,
489
+ () => connection.prepare (exception: Exception ("failed" )),
490
+ errorMessage: 'Failed to reach server. Will retry' ,
491
+ failureCountNofityThreshold: 5 );
479
492
480
493
checkRetry ('retries on ZulipApiException' ,
481
494
() => connection.prepare (httpStatus: 400 , json: {
0 commit comments