Skip to content

Commit 1112d69

Browse files
committed
store test [nfc]: Pull out helpers checkReported and friends
These will help us test the reporting behavior on a wider variety of exceptions.
1 parent d772b1f commit 1112d69

File tree

1 file changed

+50
-36
lines changed

1 file changed

+50
-36
lines changed

test/model/store_test.dart

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -803,52 +803,66 @@ void main() {
803803
check(store).isLoading.isTrue();
804804
}
805805

806-
test('report non-transient errors', () => awaitFakeAsync((async) async {
807-
await prepare();
806+
Subject<String> checkReported(void Function() prepareError) {
807+
return awaitFakeAsync((async) async {
808+
await prepare();
809+
prepareError();
810+
pollAndFail(async);
811+
return check(takeLastReportedError()).isNotNull();
812+
});
813+
}
808814

809-
prepareZulipApiExceptionBadRequest();
810-
pollAndFail(async);
811-
check(takeLastReportedError()).isNotNull().startsWith(
812-
"Error connecting to Zulip. Retrying…\n"
813-
"Error connecting to Zulip at");
814-
}));
815+
Subject<String> checkLateReported(void Function() prepareError) {
816+
return awaitFakeAsync((async) async {
817+
await prepare();
818+
819+
for (int i = 0; i < UpdateMachine.transientFailureCountNotifyThreshold; i++) {
820+
prepareError();
821+
pollAndFail(async);
822+
check(takeLastReportedError()).isNull();
823+
async.flushTimers();
824+
}
825+
826+
prepareError();
827+
pollAndFail(async);
828+
return check(takeLastReportedError()).isNotNull();
829+
});
830+
}
815831

816-
test('report transient errors', () => awaitFakeAsync((async) async {
817-
await prepare();
832+
void checkNotReported(void Function() prepareError) {
833+
return awaitFakeAsync((async) async {
834+
await prepare();
818835

819-
// There should be no user visible error messages during these retries.
820-
for (int i = 0; i < UpdateMachine.transientFailureCountNotifyThreshold; i++) {
821-
prepareServer5xxException();
836+
for (int i = 0; i < UpdateMachine.transientFailureCountNotifyThreshold; i++) {
837+
prepareError();
838+
pollAndFail(async);
839+
check(takeLastReportedError()).isNull();
840+
async.flushTimers();
841+
}
842+
843+
prepareError();
822844
pollAndFail(async);
845+
// Still no error reported, even after the same number of iterations
846+
// where other errors get reported (as [checkLateReported] checks).
823847
check(takeLastReportedError()).isNull();
824-
// This skips the pending polling backoff.
825-
async.flushTimers();
826-
}
848+
});
849+
}
827850

828-
prepareServer5xxException();
829-
pollAndFail(async);
830-
check(takeLastReportedError()).isNotNull().startsWith(
851+
test('report generic ZulipApiException', () {
852+
checkReported(prepareZulipApiExceptionBadRequest).startsWith(
831853
"Error connecting to Zulip. Retrying…\n"
832854
"Error connecting to Zulip at");
833-
}));
855+
});
834856

835-
test('ignore boring errors', () => awaitFakeAsync((async) async {
836-
await prepare();
857+
test('eventually report Server5xxException', () {
858+
checkLateReported(prepareServer5xxException).startsWith(
859+
"Error connecting to Zulip. Retrying…\n"
860+
"Error connecting to Zulip at");
861+
});
837862

838-
for (int i = 0; i < UpdateMachine.transientFailureCountNotifyThreshold; i++) {
839-
prepareNetworkExceptionSocketException();
840-
pollAndFail(async);
841-
check(takeLastReportedError()).isNull();
842-
// This skips the pending polling backoff.
843-
async.flushTimers();
844-
}
845-
846-
prepareNetworkExceptionSocketException();
847-
pollAndFail(async);
848-
// Normally we start showing user visible error messages for transient
849-
// errors after enough number of retries.
850-
check(takeLastReportedError()).isNull();
851-
}));
863+
test('ignore NetworkException from SocketException', () {
864+
checkNotReported(prepareNetworkExceptionSocketException);
865+
});
852866
});
853867
});
854868

0 commit comments

Comments
 (0)