Skip to content

Commit 99b48a4

Browse files
committed
store test [nfc]: Make a group for retry tests.
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 36c2b4d commit 99b48a4

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

test/model/store_test.dart

+41-41
Original file line numberDiff line numberDiff line change
@@ -427,53 +427,53 @@ 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();
430+
void checkRetry(String description, void Function() prepareError) {
431+
test(description, () {
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+
});
459461
});
460462
}
461463

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

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

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

475-
test('retries on MalformedServerResponseException', () {
476-
checkRetry(() => connection.prepare(httpStatus: 200, body: 'nonsense'));
475+
checkRetry('retries on MalformedServerResponseException',
476+
() => connection.prepare(httpStatus: 200, body: 'nonsense'));
477477
});
478478
});
479479

0 commit comments

Comments
 (0)