Skip to content

Commit 51b1f27

Browse files
committed
store test: Make a group for retry tests
Signed-off-by: Zixuan James Li <[email protected]>
1 parent ad95ad9 commit 51b1f27

File tree

1 file changed

+45
-43
lines changed

1 file changed

+45
-43
lines changed

test/model/store_test.dart

+45-43
Original file line numberDiff line numberDiff line change
@@ -427,53 +427,55 @@ void main() {
427427
check(store.userSettings!.twentyFourHourTime).isTrue();
428428
}));
429429

430-
void checkRetry(void Function() prepareError) {
431-
awaitFakeAsync((async) async {
432-
await prepareStore(lastEventId: 1);
433-
updateMachine.debugPauseLoop();
434-
updateMachine.poll();
435-
check(async.pendingTimers).length.equals(0);
436-
437-
// Make the request, inducing an error in it.
438-
prepareError();
439-
updateMachine.debugAdvanceLoop();
440-
async.elapse(Duration.zero);
441-
checkLastRequest(lastEventId: 1);
442-
check(store).isLoading.isTrue();
443-
444-
// Polling doesn't resume immediately; there's a timer.
445-
check(async.pendingTimers).length.equals(1);
446-
updateMachine.debugAdvanceLoop();
447-
async.flushMicrotasks();
448-
check(connection.lastRequest).isNull();
449-
check(async.pendingTimers).length.equals(1);
450-
451-
// Polling continues after a timer.
452-
connection.prepare(json: GetEventsResult(events: [
453-
HeartbeatEvent(id: 2),
454-
], queueId: null).toJson());
455-
async.flushTimers();
456-
checkLastRequest(lastEventId: 1);
457-
check(updateMachine.lastEventId).equals(2);
458-
check(store).isLoading.isFalse();
459-
});
460-
}
430+
group('retries on errors', () {
431+
void checkRetry(void Function() prepareError) {
432+
awaitFakeAsync((async) async {
433+
await prepareStore(lastEventId: 1);
434+
updateMachine.debugPauseLoop();
435+
updateMachine.poll();
436+
check(async.pendingTimers).length.equals(0);
437+
438+
// Make the request, inducing an error in it.
439+
prepareError();
440+
updateMachine.debugAdvanceLoop();
441+
async.elapse(Duration.zero);
442+
checkLastRequest(lastEventId: 1);
443+
check(store).isLoading.isTrue();
444+
445+
// Polling doesn't resume immediately; there's a timer.
446+
check(async.pendingTimers).length.equals(1);
447+
updateMachine.debugAdvanceLoop();
448+
async.flushMicrotasks();
449+
check(connection.lastRequest).isNull();
450+
check(async.pendingTimers).length.equals(1);
451+
452+
// Polling continues after a timer.
453+
connection.prepare(json: GetEventsResult(events: [
454+
HeartbeatEvent(id: 2),
455+
], queueId: null).toJson());
456+
async.flushTimers();
457+
checkLastRequest(lastEventId: 1);
458+
check(updateMachine.lastEventId).equals(2);
459+
check(store).isLoading.isFalse();
460+
});
461+
}
461462

462-
test('retries on Server5xxException', () {
463-
checkRetry(() => connection.prepare(httpStatus: 500, body: 'splat'));
464-
});
463+
test('Server5xxException', () {
464+
checkRetry(() => connection.prepare(httpStatus: 500, body: 'splat'));
465+
});
465466

466-
test('retries on NetworkException', () {
467-
checkRetry(() => connection.prepare(exception: Exception("failed")));
468-
});
467+
test('NetworkException', () {
468+
checkRetry(() => connection.prepare(exception: Exception("failed")));
469+
});
469470

470-
test('retries on ZulipApiException', () {
471-
checkRetry(() => connection.prepare(httpStatus: 400, json: {
472-
'result': 'error', 'code': 'BAD_REQUEST', 'msg': 'Bad request'}));
473-
});
471+
test('ZulipApiException', () {
472+
checkRetry(() => connection.prepare(httpStatus: 400, json: {
473+
'result': 'error', 'code': 'BAD_REQUEST', 'msg': 'Bad request'}));
474+
});
474475

475-
test('retries on MalformedServerResponseException', () {
476-
checkRetry(() => connection.prepare(httpStatus: 200, body: 'nonsense'));
476+
test('MalformedServerResponseException', () {
477+
checkRetry(() => connection.prepare(httpStatus: 200, body: 'nonsense'));
478+
});
477479
});
478480
});
479481

0 commit comments

Comments
 (0)