@@ -431,25 +431,32 @@ void main() {
431
431
group ('retry on errors' , () {
432
432
void checkRetry (void Function () prepareError, {
433
433
String ? errorMessage,
434
+ int failureCountNofityThreshold = 0 ,
434
435
}) {
435
436
awaitFakeAsync ((async ) async {
436
437
await prepareStore (lastEventId: 1 );
437
438
updateMachine.debugPauseLoop ();
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 (debugTakeLastReportedError ()).isNull ();
448
- } else {
449
- check (debugTakeLastReportedError ()).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
+ check (debugTakeLastReportedError ()).isNotNull ().contains (errorMessage);
456
+ }
457
+ checkLastRequest (lastEventId: 1 );
458
+ check (store).isLoading.isTrue ();
450
459
}
451
- checkLastRequest (lastEventId: 1 );
452
- check (store).isLoading.isTrue ();
453
460
454
461
// Polling doesn't resume immediately; there's a timer.
455
462
check (async .pendingTimers).length.equals (1 );
@@ -470,11 +477,15 @@ void main() {
470
477
}
471
478
472
479
test ('Server5xxException' , () {
473
- checkRetry (() => connection.prepare (httpStatus: 500 , body: 'splat' ));
480
+ checkRetry (() => connection.prepare (httpStatus: 500 , body: 'splat' ),
481
+ errorMessage: 'Failed to reach server. Will retry' ,
482
+ failureCountNofityThreshold: 5 );
474
483
});
475
484
476
485
test ('NetworkException' , () {
477
- checkRetry (() => connection.prepare (exception: Exception ("failed" )));
486
+ checkRetry (() => connection.prepare (exception: Exception ("failed" )),
487
+ errorMessage: 'Failed to reach server. Will retry' ,
488
+ failureCountNofityThreshold: 5 );
478
489
});
479
490
480
491
test ('ZulipApiException' , () {
0 commit comments