@@ -23,60 +23,56 @@ import { spec } from './spec_builder';
23
23
import { TimerId } from '../../../src/util/async_queue' ;
24
24
25
25
describeSpec ( 'Offline:' , [ ] , ( ) => {
26
- specTest (
27
- 'Empty queries are resolved if client goes offline' ,
28
- [ 'no-android' , 'no-ios' ] ,
29
- ( ) => {
30
- const query = Query . atPath ( path ( 'collection' ) ) ;
31
- return (
32
- spec ( )
33
- . userListens ( query )
34
- . watchStreamCloses ( Code . UNAVAILABLE )
35
- . expectEvents ( query , {
36
- fromCache : true ,
37
- hasPendingWrites : false
38
- } )
39
- // no further events
40
- . watchStreamCloses ( Code . UNAVAILABLE )
41
- . watchStreamCloses ( Code . UNAVAILABLE )
42
- ) ;
43
- }
44
- ) ;
26
+ specTest ( 'Empty queries are resolved if client goes offline' , [ ] , ( ) => {
27
+ const query = Query . atPath ( path ( 'collection' ) ) ;
28
+ return (
29
+ spec ( )
30
+ . userListens ( query )
31
+ // second error triggers event
32
+ . watchStreamCloses ( Code . UNAVAILABLE )
33
+ . watchStreamCloses ( Code . UNAVAILABLE )
34
+ . expectEvents ( query , {
35
+ fromCache : true ,
36
+ hasPendingWrites : false
37
+ } )
38
+ // no further events
39
+ . watchStreamCloses ( Code . UNAVAILABLE )
40
+ . watchStreamCloses ( Code . UNAVAILABLE )
41
+ ) ;
42
+ } ) ;
45
43
46
- specTest (
47
- 'A successful message delays offline status' ,
48
- [ 'no-android' , 'no-ios' ] ,
49
- ( ) => {
50
- const query = Query . atPath ( path ( 'collection' ) ) ;
51
- return (
52
- spec ( )
53
- . userListens ( query )
54
- . watchAcks ( query )
55
- // first error triggers unknown state
56
- . watchStreamCloses ( Code . UNAVAILABLE )
57
- // second error triggers offline state
58
- . watchStreamCloses ( Code . UNAVAILABLE )
59
- . expectEvents ( query , {
60
- fromCache : true ,
61
- hasPendingWrites : false
62
- } )
63
- // no further events
64
- . watchStreamCloses ( Code . UNAVAILABLE )
65
- . watchStreamCloses ( Code . UNAVAILABLE )
66
- ) ;
67
- }
68
- ) ;
44
+ specTest ( 'A successful message delays offline status' , [ ] , ( ) => {
45
+ const query = Query . atPath ( path ( 'collection' ) ) ;
46
+ return (
47
+ spec ( )
48
+ . userListens ( query )
49
+ . watchAcks ( query )
50
+ // first error triggers unknown state
51
+ . watchStreamCloses ( Code . UNAVAILABLE )
52
+ // getting two more errors triggers offline state
53
+ . watchStreamCloses ( Code . UNAVAILABLE )
54
+ . watchStreamCloses ( Code . UNAVAILABLE )
55
+ . expectEvents ( query , {
56
+ fromCache : true ,
57
+ hasPendingWrites : false
58
+ } )
59
+ // no further events
60
+ . watchStreamCloses ( Code . UNAVAILABLE )
61
+ . watchStreamCloses ( Code . UNAVAILABLE )
62
+ ) ;
63
+ } ) ;
69
64
70
65
specTest (
71
66
'Removing all listeners delays "Offline" status on next listen' ,
72
- [ 'eager-gc' , 'no-android' , 'no-ios' ] ,
67
+ [ 'eager-gc' ] ,
73
68
'Marked as no-lru because when a listen is re-added, it gets a new target id rather than reusing one' ,
74
69
( ) => {
75
70
const query = Query . atPath ( path ( 'collection' ) ) ;
76
71
return (
77
72
spec ( )
78
73
. userListens ( query )
79
- // error triggers offline state
74
+ // getting two errors triggers offline state
75
+ . watchStreamCloses ( Code . UNAVAILABLE )
80
76
. watchStreamCloses ( Code . UNAVAILABLE )
81
77
. expectEvents ( query , {
82
78
fromCache : true ,
@@ -87,10 +83,11 @@ describeSpec('Offline:', [], () => {
87
83
// If the next (already scheduled) connection attempt fails, we'll move
88
84
// to unknown since there are no listeners, and stop trying to connect.
89
85
. watchStreamCloses ( Code . UNAVAILABLE )
90
- // Suppose sometime later we listen again, it should take one failure
86
+ // Suppose sometime later we listen again, it should take two failures
91
87
// before we get cached data.
92
88
. userListens ( query )
93
89
. watchStreamCloses ( Code . UNAVAILABLE )
90
+ . watchStreamCloses ( Code . UNAVAILABLE )
94
91
. expectEvents ( query , {
95
92
fromCache : true ,
96
93
hasPendingWrites : false
@@ -99,62 +96,56 @@ describeSpec('Offline:', [], () => {
99
96
}
100
97
) ;
101
98
102
- specTest (
103
- 'Queries revert to fromCache=true when offline.' ,
104
- [ 'no-android' , 'no-ios' ] ,
105
- ( ) => {
106
- const query = Query . atPath ( path ( 'collection' ) ) ;
107
- const docA = doc ( 'collection/a' , 1000 , { key : 'a' } ) ;
108
- return (
109
- spec ( )
110
- . userListens ( query )
111
- . watchAcksFull ( query , 1000 , docA )
112
- . expectEvents ( query , { added : [ docA ] } )
113
- // first error triggers unknown state
114
- . watchStreamCloses ( Code . UNAVAILABLE )
115
- . restoreListen ( query , 'resume-token-1000' )
116
- // second error triggers offline state and fromCache: true
117
- . watchStreamCloses ( Code . UNAVAILABLE )
118
- . expectEvents ( query , { fromCache : true } )
119
- // Going online and getting a CURRENT message triggers fromCache: false
120
- . watchAcksFull ( query , 1000 )
121
- . expectEvents ( query , { fromCache : false } )
122
- ) ;
123
- }
124
- ) ;
99
+ specTest ( 'Queries revert to fromCache=true when offline.' , [ ] , ( ) => {
100
+ const query = Query . atPath ( path ( 'collection' ) ) ;
101
+ const docA = doc ( 'collection/a' , 1000 , { key : 'a' } ) ;
102
+ return (
103
+ spec ( )
104
+ . userListens ( query )
105
+ . watchAcksFull ( query , 1000 , docA )
106
+ . expectEvents ( query , { added : [ docA ] } )
107
+ // first error triggers unknown state
108
+ . watchStreamCloses ( Code . UNAVAILABLE )
109
+ . restoreListen ( query , 'resume-token-1000' )
110
+ // getting two more errors triggers offline state and fromCache: true
111
+ . watchStreamCloses ( Code . UNAVAILABLE )
112
+ . watchStreamCloses ( Code . UNAVAILABLE )
113
+ . expectEvents ( query , { fromCache : true } )
114
+ // Going online and getting a CURRENT message triggers fromCache: false
115
+ . watchAcksFull ( query , 1000 )
116
+ . expectEvents ( query , { fromCache : false } )
117
+ ) ;
118
+ } ) ;
125
119
126
- specTest (
127
- 'Queries with limbo documents handle going offline.' ,
128
- [ 'no-android' , 'no-ios' ] ,
129
- ( ) => {
130
- const query = Query . atPath ( path ( 'collection' ) ) ;
131
- const docA = doc ( 'collection/a' , 1000 , { key : 'a' } ) ;
132
- const limboQuery = Query . atPath ( docA . key . path ) ;
133
- return (
134
- spec ( )
135
- . userListens ( query )
136
- . watchAcksFull ( query , 1000 , docA )
137
- . expectEvents ( query , { added : [ docA ] } )
138
- . watchResets ( query )
139
- // No more documents
140
- . watchCurrents ( query , 'resume-token-1001' )
141
- . watchSnapshots ( 1001 )
142
- // docA will now be in limbo (triggering fromCache=true)
143
- . expectLimboDocs ( docA . key )
144
- . expectEvents ( query , { fromCache : true } )
145
- // first error triggers unknown state
146
- . watchStreamCloses ( Code . UNAVAILABLE )
147
- . restoreListen ( query , 'resume-token-1001' )
148
- // second error triggers offline state.
149
- . watchStreamCloses ( Code . UNAVAILABLE )
150
- . watchAcksFull ( query , 1001 )
151
- . watchAcksFull ( limboQuery , 1001 )
152
- // Limbo document is resolved. No longer from cache.
153
- . expectEvents ( query , { removed : [ docA ] , fromCache : false } )
154
- . expectLimboDocs ( )
155
- ) ;
156
- }
157
- ) ;
120
+ specTest ( 'Queries with limbo documents handle going offline.' , [ ] , ( ) => {
121
+ const query = Query . atPath ( path ( 'collection' ) ) ;
122
+ const docA = doc ( 'collection/a' , 1000 , { key : 'a' } ) ;
123
+ const limboQuery = Query . atPath ( docA . key . path ) ;
124
+ return (
125
+ spec ( )
126
+ . userListens ( query )
127
+ . watchAcksFull ( query , 1000 , docA )
128
+ . expectEvents ( query , { added : [ docA ] } )
129
+ . watchResets ( query )
130
+ // No more documents
131
+ . watchCurrents ( query , 'resume-token-1001' )
132
+ . watchSnapshots ( 1001 )
133
+ // docA will now be in limbo (triggering fromCache=true)
134
+ . expectLimboDocs ( docA . key )
135
+ . expectEvents ( query , { fromCache : true } )
136
+ // first error triggers unknown state
137
+ . watchStreamCloses ( Code . UNAVAILABLE )
138
+ . restoreListen ( query , 'resume-token-1001' )
139
+ // getting two more errors triggers offline state.
140
+ . watchStreamCloses ( Code . UNAVAILABLE )
141
+ . watchStreamCloses ( Code . UNAVAILABLE )
142
+ . watchAcksFull ( query , 1001 )
143
+ . watchAcksFull ( limboQuery , 1001 )
144
+ // Limbo document is resolved. No longer from cache.
145
+ . expectEvents ( query , { removed : [ docA ] , fromCache : false } )
146
+ . expectLimboDocs ( )
147
+ ) ;
148
+ } ) ;
158
149
159
150
specTest ( 'OnlineState timeout triggers offline behavior' , [ ] , ( ) => {
160
151
const query = Query . atPath ( path ( 'collection' ) ) ;
@@ -193,16 +184,17 @@ describeSpec('Offline:', [], () => {
193
184
specTest (
194
185
'New queries return immediately with fromCache=true when offline due to ' +
195
186
'stream failures.' ,
196
- [ 'no-android' , 'no-ios' ] ,
187
+ [ ] ,
197
188
( ) => {
198
189
const query1 = Query . atPath ( path ( 'collection' ) ) ;
199
190
const query2 = Query . atPath ( path ( 'collection2' ) ) ;
200
191
return (
201
192
spec ( )
202
193
. userListens ( query1 )
203
- // After failure, we mark the client offline and trigger an empty
194
+ // 2 Failures should mark the client offline and trigger an empty
204
195
// fromCache event.
205
196
. watchStreamCloses ( Code . UNAVAILABLE )
197
+ . watchStreamCloses ( Code . UNAVAILABLE )
206
198
. expectEvents ( query1 , { fromCache : true } )
207
199
208
200
// A new query should immediately return from cache.
0 commit comments