16
16
*/
17
17
18
18
import { Query } from '../../../src/core/query' ;
19
- import { doc , path , TestSnapshotVersion , version } from '../../util/helpers' ;
19
+ import {
20
+ doc ,
21
+ path ,
22
+ TestSnapshotVersion ,
23
+ version ,
24
+ wrapObject
25
+ } from '../../util/helpers' ;
20
26
21
27
import { describeSpec , specTest } from './describe_spec' ;
22
28
import { client , spec } from './spec_builder' ;
@@ -26,17 +32,17 @@ import {
26
32
TEST_DATABASE_ID
27
33
} from '../local/persistence_test_helpers' ;
28
34
import { DocumentKey } from '../../../src/model/document_key' ;
29
- import * as api from '../../../src/protos/firestore_proto_api' ;
30
- import { Value } from '../../../src/protos/firestore_proto_api' ;
31
35
import { toVersion } from '../../../src/remote/serializer' ;
36
+ import { JsonObject } from '../../../src/model/object_value' ;
32
37
33
38
interface TestBundleDocument {
34
39
key : DocumentKey ;
35
40
readTime : TestSnapshotVersion ;
36
41
createTime ?: TestSnapshotVersion ;
37
42
updateTime ?: TestSnapshotVersion ;
38
- content ?: api . ApiClientObjectMap < Value > ;
43
+ content ?: JsonObject < unknown > ;
39
44
}
45
+
40
46
function bundleWithDocument ( testDoc : TestBundleDocument ) : string {
41
47
const builder = new TestBundleBuilder ( TEST_DATABASE_ID ) ;
42
48
builder . addDocumentMetadata (
@@ -49,7 +55,7 @@ function bundleWithDocument(testDoc: TestBundleDocument): string {
49
55
testDoc . key ,
50
56
toVersion ( JSON_SERIALIZER , version ( testDoc . createTime ) ) ,
51
57
toVersion ( JSON_SERIALIZER , version ( testDoc . updateTime ! ) ) ,
52
- testDoc . content !
58
+ wrapObject ( testDoc . content ! ) . proto . mapValue . fields !
53
59
) ;
54
60
}
55
61
return builder . build (
@@ -69,33 +75,37 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
69
75
readTime : 3000 ,
70
76
createTime : 1999 ,
71
77
updateTime : 2999 ,
72
- content : { key : { stringValue : 'b' } }
78
+ content : { key : 'b' }
73
79
} ) ;
74
80
75
81
return spec ( )
76
82
. userListens ( query1 )
77
83
. watchAcksFull ( query1 , 1000 , docA )
78
84
. expectEvents ( query1 , { added : [ docA ] } )
79
85
. loadBundle ( bundleString )
80
- . expectEvents ( query1 , { modified : [ docAChanged ] , fromCache : true } ) ;
86
+ . expectEvents ( query1 , { modified : [ docAChanged ] } ) ;
81
87
} ) ;
82
88
83
- specTest ( 'Newer deleted docs from bundles should delete cache' , [ ] , ( ) => {
84
- const query1 = Query . atPath ( path ( 'collection' ) ) ;
85
- const docA = doc ( 'collection/a' , 1000 , { key : 'a' } ) ;
89
+ specTest (
90
+ 'Newer deleted docs from bundles should delete cache docs' ,
91
+ [ ] ,
92
+ ( ) => {
93
+ const query1 = Query . atPath ( path ( 'collection' ) ) ;
94
+ const docA = doc ( 'collection/a' , 1000 , { key : 'a' } ) ;
86
95
87
- const bundleString = bundleWithDocument ( {
88
- key : docA . key ,
89
- readTime : 3000
90
- } ) ;
96
+ const bundleString = bundleWithDocument ( {
97
+ key : docA . key ,
98
+ readTime : 3000
99
+ } ) ;
91
100
92
- return spec ( )
93
- . userListens ( query1 )
94
- . watchAcksFull ( query1 , 1000 , docA )
95
- . expectEvents ( query1 , { added : [ docA ] } )
96
- . loadBundle ( bundleString )
97
- . expectEvents ( query1 , { removed : [ docA ] , fromCache : true } ) ;
98
- } ) ;
101
+ return spec ( )
102
+ . userListens ( query1 )
103
+ . watchAcksFull ( query1 , 1000 , docA )
104
+ . expectEvents ( query1 , { added : [ docA ] } )
105
+ . loadBundle ( bundleString )
106
+ . expectEvents ( query1 , { removed : [ docA ] } ) ;
107
+ }
108
+ ) ;
99
109
100
110
specTest ( 'Older deleted docs from bundles should do nothing' , [ ] , ( ) => {
101
111
const query1 = Query . atPath ( path ( 'collection' ) ) ;
@@ -117,7 +127,7 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
117
127
} ) ;
118
128
119
129
specTest (
120
- 'Newer docs from bundles should raise snapshot only when watch catches up with acknowledged writes' ,
130
+ 'Newer docs from bundles should raise snapshot only when Watch catches up with acknowledged writes' ,
121
131
[ ] ,
122
132
( ) => {
123
133
const query = Query . atPath ( path ( 'collection' ) ) ;
@@ -128,18 +138,20 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
128
138
readTime : 500 ,
129
139
createTime : 250 ,
130
140
updateTime : 500 ,
131
- content : { key : { stringValue : 'b' } }
141
+ content : { key : 'b' }
132
142
} ) ;
133
143
134
144
const bundleAfterMutationAck = bundleWithDocument ( {
135
145
key : docA . key ,
136
146
readTime : 1001 ,
137
147
createTime : 250 ,
138
148
updateTime : 1001 ,
139
- content : { key : { stringValue : 'fromBundle' } }
149
+ content : { key : 'fromBundle' }
140
150
} ) ;
141
151
return (
142
152
spec ( )
153
+ // TODO(b/160878667): Figure out what happens when memory eager GC is on
154
+ // a bundle is loaded.
143
155
. withGCEnabled ( false )
144
156
. userListens ( query )
145
157
. watchAcksFull ( query , 250 , docA )
@@ -166,8 +178,7 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
166
178
// the acknowledged mutation.
167
179
. loadBundle ( bundleAfterMutationAck )
168
180
. expectEvents ( query , {
169
- modified : [ doc ( 'collection/a' , 1001 , { key : 'fromBundle' } ) ] ,
170
- fromCache : true
181
+ modified : [ doc ( 'collection/a' , 1001 , { key : 'fromBundle' } ) ]
171
182
} )
172
183
) ;
173
184
}
@@ -185,7 +196,7 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
185
196
readTime : 1001 ,
186
197
createTime : 250 ,
187
198
updateTime : 1001 ,
188
- content : { key : { stringValue : 'fromBundle' } }
199
+ content : { key : 'fromBundle' }
189
200
} ) ;
190
201
191
202
return (
@@ -223,8 +234,9 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
223
234
readTime : 500 ,
224
235
createTime : 250 ,
225
236
updateTime : 500 ,
226
- content : { key : { stringValue : 'b' } }
237
+ content : { key : 'b' }
227
238
} ) ;
239
+ const limboQuery = Query . atPath ( docA . key . path ) ;
228
240
229
241
return (
230
242
spec ( )
@@ -235,11 +247,21 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
235
247
. expectEvents ( query , { } )
236
248
// Bundle tells otherwise, leads to limbo.
237
249
. loadBundle ( bundleString1 )
250
+ . expectLimboDocs ( docA . key )
238
251
. expectEvents ( query , {
239
252
added : [ doc ( 'collection/a' , 500 , { key : 'b' } ) ] ,
240
253
fromCache : true
241
254
} )
242
- . expectLimboDocs ( docA . key )
255
+ // .watchAcksFull(limboQuery, 1002, docA1)
256
+ . watchAcks ( limboQuery )
257
+ . watchSends ( { affects : [ limboQuery ] } )
258
+ . watchCurrents ( limboQuery , 'resume-token-1002' )
259
+ . watchSnapshots ( 1002 )
260
+ . expectLimboDocs ( )
261
+ . expectEvents ( query , {
262
+ removed : [ doc ( 'collection/a' , 500 , { key : 'b' } ) ] ,
263
+ fromCache : false
264
+ } )
243
265
) ;
244
266
} ) ;
245
267
@@ -254,7 +276,7 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
254
276
readTime : 500 ,
255
277
createTime : 250 ,
256
278
updateTime : 500 ,
257
- content : { key : { stringValue : 'b' } }
279
+ content : { key : 'b' }
258
280
} ) ;
259
281
260
282
return client ( 0 )
@@ -286,7 +308,7 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
286
308
readTime : 500 ,
287
309
createTime : 250 ,
288
310
updateTime : 500 ,
289
- content : { key : { stringValue : 'b' } }
311
+ content : { key : 'b' }
290
312
} ) ;
291
313
292
314
return client ( 0 )
@@ -302,8 +324,7 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
302
324
} )
303
325
. loadBundle ( bundleString1 )
304
326
. expectEvents ( query , {
305
- modified : [ doc ( 'collection/a' , 500 , { key : 'b' } ) ] ,
306
- fromCache : true
327
+ modified : [ doc ( 'collection/a' , 500 , { key : 'b' } ) ]
307
328
} ) ;
308
329
}
309
330
) ;
@@ -319,7 +340,7 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
319
340
readTime : 500 ,
320
341
createTime : 250 ,
321
342
updateTime : 500 ,
322
- content : { key : { stringValue : 'b' } }
343
+ content : { key : 'b' }
323
344
} ) ;
324
345
325
346
return client ( 0 )
@@ -336,13 +357,11 @@ describeSpec('Bundles:', ['no-ios', 'no-android'], () => {
336
357
. client ( 0 )
337
358
. loadBundle ( bundleString1 )
338
359
. expectEvents ( query , {
339
- modified : [ doc ( 'collection/a' , 500 , { key : 'b' } ) ] ,
340
- fromCache : true
360
+ modified : [ doc ( 'collection/a' , 500 , { key : 'b' } ) ]
341
361
} )
342
362
. client ( 1 )
343
363
. expectEvents ( query , {
344
- modified : [ doc ( 'collection/a' , 500 , { key : 'b' } ) ] ,
345
- fromCache : true
364
+ modified : [ doc ( 'collection/a' , 500 , { key : 'b' } ) ]
346
365
} ) ;
347
366
}
348
367
) ;
0 commit comments