@@ -140,18 +140,26 @@ void main() {
140
140
});
141
141
142
142
group ('UpdateMachine.poll' , () {
143
+ late TestGlobalStore globalStore;
143
144
late UpdateMachine updateMachine;
144
145
late PerAccountStore store;
145
146
late FakeApiConnection connection;
146
147
147
- void prepareStore ({int ? lastEventId}) {
148
- updateMachine = eg.updateMachine (initialSnapshot: eg.initialSnapshot (
149
- lastEventId: lastEventId,
150
- ));
148
+ void updateFromGlobalStore () {
149
+ updateMachine = globalStore.updateMachines[eg.selfAccount.id]! ;
151
150
store = updateMachine.store;
151
+ assert (identical (store, globalStore.perAccountSync (eg.selfAccount.id)));
152
152
connection = store.connection as FakeApiConnection ;
153
153
}
154
154
155
+ Future <void > prepareStore ({int ? lastEventId}) async {
156
+ globalStore = TestGlobalStore (accounts: []);
157
+ await globalStore.add (eg.selfAccount, eg.initialSnapshot (
158
+ lastEventId: lastEventId));
159
+ await globalStore.perAccount (eg.selfAccount.id);
160
+ updateFromGlobalStore ();
161
+ }
162
+
155
163
void checkLastRequest ({required int lastEventId}) {
156
164
check (connection.lastRequest).isA< http.Request > ()
157
165
..method.equals ('GET' )
@@ -163,7 +171,7 @@ void main() {
163
171
}
164
172
165
173
test ('loops on success' , () async {
166
- prepareStore (lastEventId: 1 );
174
+ await prepareStore (lastEventId: 1 );
167
175
check (updateMachine.lastEventId).equals (1 );
168
176
169
177
updateMachine.debugPauseLoop ();
@@ -191,7 +199,7 @@ void main() {
191
199
});
192
200
193
201
test ('handles events' , () async {
194
- prepareStore ();
202
+ await prepareStore ();
195
203
updateMachine.debugPauseLoop ();
196
204
updateMachine.poll ();
197
205
@@ -206,6 +214,40 @@ void main() {
206
214
await Future .delayed (Duration .zero);
207
215
check (store.userSettings! .twentyFourHourTime).isTrue ();
208
216
});
217
+
218
+ test ('handles expired queue' , () async {
219
+ await prepareStore ();
220
+ updateMachine.debugPauseLoop ();
221
+ updateMachine.poll ();
222
+ check (globalStore.perAccountSync (store.account.id)).identicalTo (store);
223
+
224
+ // Let the server expire the event queue.
225
+ connection.prepare (httpStatus: 400 , json: {
226
+ 'result' : 'error' , 'code' : 'BAD_EVENT_QUEUE_ID' ,
227
+ 'queue_id' : updateMachine.queueId,
228
+ 'msg' : 'Bad event queue ID: ${updateMachine .queueId }' ,
229
+ });
230
+ updateMachine.debugAdvanceLoop ();
231
+ await null ;
232
+ await Future .delayed (Duration .zero);
233
+
234
+ // The global store has a new store.
235
+ check (globalStore.perAccountSync (store.account.id)).not (it ()..identicalTo (store));
236
+ updateFromGlobalStore ();
237
+
238
+ // The new UpdateMachine updates the new store.
239
+ updateMachine.debugPauseLoop ();
240
+ updateMachine.poll ();
241
+ check (store.userSettings! .twentyFourHourTime).isFalse ();
242
+ connection.prepare (json: GetEventsResult (events: [
243
+ UserSettingsUpdateEvent (id: 2 ,
244
+ property: UserSettingName .twentyFourHourTime, value: true ),
245
+ ], queueId: null ).toJson ());
246
+ updateMachine.debugAdvanceLoop ();
247
+ await null ;
248
+ await Future .delayed (Duration .zero);
249
+ check (store.userSettings! .twentyFourHourTime).isTrue ();
250
+ });
209
251
});
210
252
211
253
group ('UpdateMachine.registerNotificationToken' , () {
0 commit comments