@@ -8,6 +8,7 @@ import 'package:zulip/api/model/events.dart';
88import 'package:zulip/api/model/model.dart' ;
99import 'package:zulip/api/route/events.dart' ;
1010import 'package:zulip/api/route/messages.dart' ;
11+ import 'package:zulip/log.dart' ;
1112import 'package:zulip/model/store.dart' ;
1213import 'package:zulip/notifications/receive.dart' ;
1314
@@ -427,53 +428,61 @@ void main() {
427428 check (store.userSettings! .twentyFourHourTime).isTrue ();
428429 }));
429430
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- });
431+ void checkRetry (void Function () prepareError, {
432+ String ? errorMessage,
433+ }) {
434+ awaitFakeAsync ((async ) async {
435+ await prepareStore (lastEventId: 1 );
436+ updateMachine.debugPauseLoop ();
437+ updateMachine.poll ();
438+ check (async .pendingTimers).length.equals (0 );
439+
440+ // Make the request, inducing an error in it.
441+ prepareError ();
442+ updateMachine.debugAdvanceLoop ();
443+ check (debugLastReportedError).isNull ();
444+ async .elapse (Duration .zero);
445+ if (errorMessage == null ) {
446+ check (debugTakeLastReportedError ()).isNull ();
447+ } else {
448+ check (debugTakeLastReportedError ()).isNotNull ().contains (errorMessage);
449+ }
450+ checkLastRequest (lastEventId: 1 );
451+ check (store).isLoading.isTrue ();
452+
453+ // Polling doesn't resume immediately; there's a timer.
454+ check (async .pendingTimers).length.equals (1 );
455+ updateMachine.debugAdvanceLoop ();
456+ async .flushMicrotasks ();
457+ check (connection.lastRequest).isNull ();
458+ check (async .pendingTimers).length.equals (1 );
459+
460+ // Polling continues after a timer.
461+ connection.prepare (json: GetEventsResult (events: [
462+ HeartbeatEvent (id: 2 ),
463+ ], queueId: null ).toJson ());
464+ async .flushTimers ();
465+ checkLastRequest (lastEventId: 1 );
466+ check (updateMachine.lastEventId).equals (2 );
467+ check (store).isLoading.isFalse ();
461468 });
462469 }
463470
464471 group ('retries' , () {
465- checkRetry ('retries on Server5xxException' ,
466- ( ) => connection.prepare (httpStatus: 500 , body: 'splat' ));
472+ test ('retries on Server5xxException' , () =>
473+ checkRetry (( ) => connection.prepare (httpStatus: 500 , body: 'splat' ) ));
467474
468- checkRetry ('retries on NetworkException' ,
469- ( ) => connection.prepare (exception: Exception ("failed" )));
475+ test ('retries on NetworkException' , () =>
476+ checkRetry (( ) => connection.prepare (exception: Exception ("failed" ) )));
470477
471- checkRetry ('retries on ZulipApiException' ,
472- () => connection.prepare (httpStatus: 400 , json: {
473- 'result' : 'error' , 'code' : 'BAD_REQUEST' , 'msg' : 'Bad request' }));
478+ test ('retries on ZulipApiException' , () =>
479+ checkRetry (() => connection.prepare (httpStatus: 400 , json: {
480+ 'result' : 'error' , 'code' : 'BAD_REQUEST' , 'msg' : 'Bad request' }),
481+ errorMessage: 'Error loading server data. Will retry' ));
474482
475- checkRetry ('retries on MalformedServerResponseException' ,
476- () => connection.prepare (httpStatus: 200 , body: 'nonsense' ));
483+ test ('retries on MalformedServerResponseException' , () =>
484+ checkRetry (() => connection.prepare (httpStatus: 200 , body: 'nonsense' ),
485+ errorMessage: 'Error loading server data. Will retry' ));
477486 });
478487 });
479488
0 commit comments