|
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 verifies that the first user-facing error message when the |
| 480 | + /// By default, verify that the first user-facing error message when the |
480 | 481 | /// `numRetries`'th polling failure occurs.
|
| 482 | + /// |
| 483 | + /// If `expectNotifyError` is false, verify that there is no user-facing |
| 484 | + /// error message regardless of the retries. |
481 | 485 | void checkRetry(void Function() prepareError, {
|
482 | 486 | required int numRetries,
|
| 487 | + bool expectNotifyError = true, |
483 | 488 | }) {
|
484 | 489 | assert(numRetries > 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 < numRetries - 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 | // Only expect an error message from the last retry.
|
520 | 532 | assert(i == numRetries - 1);
|
521 | 533 | check(takeLastReportedError()).isNotNull().contains(expectedErrorMessage);
|
@@ -549,6 +561,13 @@ void main() {
|
549 | 561 | numRetries: UpdateMachine.transientFailureCountNotifyThreshold + 1);
|
550 | 562 | });
|
551 | 563 |
|
| 564 | + test('NetworkException to be ignored', () { |
| 565 | + checkRetry(() => connection.prepare( |
| 566 | + exception: const SocketException("failed")), |
| 567 | + numRetries: UpdateMachine.transientFailureCountNotifyThreshold + 1, |
| 568 | + expectNotifyError: false); |
| 569 | + }); |
| 570 | + |
552 | 571 | test('ZulipApiException', () {
|
553 | 572 | checkRetry(() => connection.prepare(httpStatus: 400, json: {
|
554 | 573 | 'result': 'error', 'code': 'BAD_REQUEST', 'msg': 'Bad request'}),
|
|
0 commit comments