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