@@ -455,53 +455,55 @@ void main() {
455
455
check (store.debugMessageListViews).isEmpty ();
456
456
}));
457
457
458
- void checkRetry (void Function () prepareError) {
459
- awaitFakeAsync ((async ) async {
460
- await prepareStore (lastEventId: 1 );
461
- updateMachine.debugPauseLoop ();
462
- updateMachine.poll ();
463
- check (async .pendingTimers).length.equals (0 );
464
-
465
- // Make the request, inducing an error in it.
466
- prepareError ();
467
- updateMachine.debugAdvanceLoop ();
468
- async .elapse (Duration .zero);
469
- checkLastRequest (lastEventId: 1 );
470
- check (store).isLoading.isTrue ();
471
-
472
- // Polling doesn't resume immediately; there's a timer.
473
- check (async .pendingTimers).length.equals (1 );
474
- updateMachine.debugAdvanceLoop ();
475
- async .flushMicrotasks ();
476
- check (connection.lastRequest).isNull ();
477
- check (async .pendingTimers).length.equals (1 );
478
-
479
- // Polling continues after a timer.
480
- connection.prepare (json: GetEventsResult (events: [
481
- HeartbeatEvent (id: 2 ),
482
- ], queueId: null ).toJson ());
483
- async .flushTimers ();
484
- checkLastRequest (lastEventId: 1 );
485
- check (updateMachine.lastEventId).equals (2 );
486
- check (store).isLoading.isFalse ();
487
- });
488
- }
458
+ group ('retries on errors' , () {
459
+ void checkRetry (void Function () prepareError) {
460
+ awaitFakeAsync ((async ) async {
461
+ await prepareStore (lastEventId: 1 );
462
+ updateMachine.debugPauseLoop ();
463
+ updateMachine.poll ();
464
+ check (async .pendingTimers).length.equals (0 );
465
+
466
+ // Make the request, inducing an error in it.
467
+ prepareError ();
468
+ updateMachine.debugAdvanceLoop ();
469
+ async .elapse (Duration .zero);
470
+ checkLastRequest (lastEventId: 1 );
471
+ check (store).isLoading.isTrue ();
472
+
473
+ // Polling doesn't resume immediately; there's a timer.
474
+ check (async .pendingTimers).length.equals (1 );
475
+ updateMachine.debugAdvanceLoop ();
476
+ async .flushMicrotasks ();
477
+ check (connection.lastRequest).isNull ();
478
+ check (async .pendingTimers).length.equals (1 );
479
+
480
+ // Polling continues after a timer.
481
+ connection.prepare (json: GetEventsResult (events: [
482
+ HeartbeatEvent (id: 2 ),
483
+ ], queueId: null ).toJson ());
484
+ async .flushTimers ();
485
+ checkLastRequest (lastEventId: 1 );
486
+ check (updateMachine.lastEventId).equals (2 );
487
+ check (store).isLoading.isFalse ();
488
+ });
489
+ }
489
490
490
- test ('retries on Server5xxException' , () {
491
- checkRetry (() => connection.prepare (httpStatus: 500 , body: 'splat' ));
492
- });
491
+ test ('Server5xxException' , () {
492
+ checkRetry (() => connection.prepare (httpStatus: 500 , body: 'splat' ));
493
+ });
493
494
494
- test ('retries on NetworkException' , () {
495
- checkRetry (() => connection.prepare (exception: Exception ("failed" )));
496
- });
495
+ test ('NetworkException' , () {
496
+ checkRetry (() => connection.prepare (exception: Exception ("failed" )));
497
+ });
497
498
498
- test ('retries on ZulipApiException' , () {
499
- checkRetry (() => connection.prepare (httpStatus: 400 , json: {
500
- 'result' : 'error' , 'code' : 'BAD_REQUEST' , 'msg' : 'Bad request' }));
501
- });
499
+ test ('ZulipApiException' , () {
500
+ checkRetry (() => connection.prepare (httpStatus: 400 , json: {
501
+ 'result' : 'error' , 'code' : 'BAD_REQUEST' , 'msg' : 'Bad request' }));
502
+ });
502
503
503
- test ('retries on MalformedServerResponseException' , () {
504
- checkRetry (() => connection.prepare (httpStatus: 200 , body: 'nonsense' ));
504
+ test ('MalformedServerResponseException' , () {
505
+ checkRetry (() => connection.prepare (httpStatus: 200 , body: 'nonsense' ));
506
+ });
505
507
});
506
508
});
507
509
0 commit comments