|
1 | 1 | import 'dart:async';
|
| 2 | +import 'dart:io'; |
2 | 3 |
|
3 | 4 | import 'package:checks/checks.dart';
|
4 | 5 | import 'package:flutter/foundation.dart';
|
@@ -476,10 +477,14 @@ void main() {
|
476 | 477 | /// Check if [UpdateMachine.poll] retries as expected when there are
|
477 | 478 | /// errors.
|
478 | 479 | ///
|
479 |
| - /// This also verifies that the first user-facing error message appears |
480 |
| - /// after the `numFailedRequests`'th failed request. |
| 480 | + /// By default, also verify that the first user-facing error message |
| 481 | + /// appears after the `numFailedRequests`'th failed request. |
| 482 | + /// |
| 483 | + /// If `expectNotifyError` is false, instead verify that there is no |
| 484 | + /// user-facing error message regardless of the retries. |
481 | 485 | void checkRetry(void Function() prepareError, {
|
482 | 486 | required int numFailedRequests,
|
| 487 | + bool expectNotifyError = true, |
483 | 488 | }) {
|
484 | 489 | assert(numFailedRequests > 0);
|
485 | 490 | reportErrorToUserBriefly = logAndReportErrorToUserBriefly;
|
@@ -510,12 +515,19 @@ void main() {
|
510 | 515 | async.flushTimers();
|
511 | 516 | }
|
512 | 517 |
|
| 518 | + if (!expectNotifyError) { |
| 519 | + // No matter how many retries there have been, no request should |
| 520 | + // result in an error message. |
| 521 | + check(takeLastReportedError()).isNull(); |
| 522 | + continue; |
| 523 | + } |
513 | 524 | if (i < numFailedRequests - 1) {
|
514 | 525 | // The error message should not appear until the `updateMachine`
|
515 | 526 | // has retried the given number of times.
|
516 | 527 | check(takeLastReportedError()).isNull();
|
517 | 528 | continue;
|
518 | 529 | }
|
| 530 | + assert(expectNotifyError); |
519 | 531 | assert(i == numFailedRequests - 1);
|
520 | 532 | check(takeLastReportedError()).isNotNull().contains(expectedErrorMessage);
|
521 | 533 | }
|
@@ -548,6 +560,13 @@ void main() {
|
548 | 560 | numFailedRequests: UpdateMachine.transientFailureCountNotifyThreshold + 1);
|
549 | 561 | });
|
550 | 562 |
|
| 563 | + test('NetworkException to be ignored', () { |
| 564 | + checkRetry(() => connection.prepare( |
| 565 | + exception: const SocketException("failed")), |
| 566 | + numFailedRequests: UpdateMachine.transientFailureCountNotifyThreshold + 1, |
| 567 | + expectNotifyError: false); |
| 568 | + }); |
| 569 | + |
551 | 570 | test('ZulipApiException', () {
|
552 | 571 | checkRetry(() => connection.prepare(httpStatus: 400, json: {
|
553 | 572 | 'result': 'error', 'code': 'BAD_REQUEST', 'msg': 'Bad request'}),
|
|
0 commit comments