@@ -471,8 +471,17 @@ void main() {
471
471
}));
472
472
473
473
group ('retries on errors' , () {
474
+ /// Check if [UpdateMachine.poll] retries as expected when there are
475
+ /// errors.
476
+ ///
477
+ /// If `expectedFailureCountNotifyThreshold` is null,
478
+ /// no user-facing error message should be shown .
479
+ ///
480
+ /// If `expectedFailureCountNotifyThreshold` is non-null,
481
+ /// the first user-facing error message should be shown when
482
+ /// the `expectedFailureCountNotifyThreshold` 'th polling failure occurs.
474
483
void checkRetry (void Function () prepareError, {
475
- int expectedFailureCountNotifyThreshold = 0 ,
484
+ int ? expectedFailureCountNotifyThreshold = 0 ,
476
485
}) {
477
486
reportErrorToUserBriefly = logAndReportErrorToUserBriefly;
478
487
addTearDown (() => reportErrorToUserBriefly = defaultReportErrorToUserBriefly);
@@ -489,7 +498,8 @@ void main() {
489
498
490
499
// Need to add 1 to the upperbound for that one additional request
491
500
// to trigger error reporting.
492
- for (int i = 0 ; i < expectedFailureCountNotifyThreshold + 1 ; i++ ) {
501
+ final numRetries = expectedFailureCountNotifyThreshold ?? 0 + 1 ;
502
+ for (int i = 0 ; i < numRetries; i++ ) {
493
503
// Make the request, inducing an error in it.
494
504
prepareError ();
495
505
if (i > 0 ) {
@@ -499,15 +509,19 @@ void main() {
499
509
updateMachine.debugAdvanceLoop ();
500
510
check (lastReportedError).isNull ();
501
511
async .elapse (Duration .zero);
502
- if (i < expectedFailureCountNotifyThreshold) {
512
+
513
+ checkLastRequest (lastEventId: 1 );
514
+ check (store).isLoading.isTrue ();
515
+ if (expectedFailureCountNotifyThreshold == null
516
+ || i < expectedFailureCountNotifyThreshold) {
503
517
// The error message should not appear until the `updateMachine`
504
518
// has retried the given number of times.
505
519
check (takeLastReportedError ()).isNull ();
506
- } else {
520
+ continue ;
521
+ }
522
+ if (i == expectedFailureCountNotifyThreshold) {
507
523
check (takeLastReportedError ()).isNotNull ().contains (expectedErrorMessage);
508
524
}
509
- checkLastRequest (lastEventId: 1 );
510
- check (store).isLoading.isTrue ();
511
525
}
512
526
513
527
// Polling doesn't resume immediately; there's a timer.
0 commit comments