{ "Local mutations are persisted and re-sent": { "describeName": "Persistence:", "itName": "Local mutations are persisted and re-sent", "tags": [ "durable-persistence" ], "config": { "useGarbageCollection": true, "numClients": 1 }, "steps": [ { "userSet": [ "collection/key1", { "foo": "bar" } ] }, { "userSet": [ "collection/key2", { "baz": "quu" } ] }, { "restart": true, "expectedState": { "activeTargets": {}, "limboDocs": [], "numOutstandingWrites": 2 } }, { "writeAck": { "version": 1 } }, { "writeAck": { "version": 2 }, "expectedState": { "numOutstandingWrites": 0 } } ] }, "Persisted local mutations are visible to listeners": { "describeName": "Persistence:", "itName": "Persisted local mutations are visible to listeners", "tags": [ "durable-persistence" ], "config": { "useGarbageCollection": true, "numClients": 1 }, "steps": [ { "userSet": [ "collection/key1", { "foo": "bar" } ] }, { "userSet": [ "collection/key2", { "baz": "quu" } ] }, { "restart": true, "expectedState": { "activeTargets": {}, "limboDocs": [] } }, { "userListen": [ 2, { "path": "collection", "filters": [], "orderBys": [] } ], "expectedState": { "activeTargets": { "2": { "queries": [ { "path": "collection", "filters": [], "orderBys": [] } ], "resumeToken": "" } } }, "expectedSnapshotEvents": [ { "query": { "path": "collection", "filters": [], "orderBys": [] }, "added": [ { "key": "collection/key1", "version": 0, "value": { "foo": "bar" }, "options": { "hasLocalMutations": true, "hasCommittedMutations": false } }, { "key": "collection/key2", "version": 0, "value": { "baz": "quu" }, "options": { "hasLocalMutations": true, "hasCommittedMutations": false } } ], "errorCode": 0, "fromCache": true, "hasPendingWrites": true } ] } ] }, "Remote documents are persisted": { "describeName": "Persistence:", "itName": "Remote documents are persisted", "tags": [ "durable-persistence" ], "config": { "useGarbageCollection": true, "numClients": 1 }, "steps": [ { "userListen": [ 2, { "path": "collection", "filters": [], "orderBys": [] } ], "expectedState": { "activeTargets": { "2": { "queries": [ { "path": "collection", "filters": [], "orderBys": [] } ], "resumeToken": "" } } } }, { "watchAck": [ 2 ] }, { "watchEntity": { "docs": [ { "key": "collection/key", "version": 1000, "value": { "foo": "bar" }, "options": { "hasLocalMutations": false, "hasCommittedMutations": false } } ], "targets": [ 2 ] } }, { "watchCurrent": [ [ 2 ], "resume-token-1000" ] }, { "watchSnapshot": { "version": 1000, "targetIds": [] }, "expectedSnapshotEvents": [ { "query": { "path": "collection", "filters": [], "orderBys": [] }, "added": [ { "key": "collection/key", "version": 1000, "value": { "foo": "bar" }, "options": { "hasLocalMutations": false, "hasCommittedMutations": false } } ], "errorCode": 0, "fromCache": false, "hasPendingWrites": false } ] }, { "restart": true, "expectedState": { "activeTargets": {}, "limboDocs": [] } }, { "userListen": [ 2, { "path": "collection", "filters": [], "orderBys": [] } ], "expectedState": { "activeTargets": { "2": { "queries": [ { "path": "collection", "filters": [], "orderBys": [] } ], "resumeToken": "resume-token-1000" } } }, "expectedSnapshotEvents": [ { "query": { "path": "collection", "filters": [], "orderBys": [] }, "added": [ { "key": "collection/key", "version": 1000, "value": { "foo": "bar" }, "options": { "hasLocalMutations": false, "hasCommittedMutations": false } } ], "errorCode": 0, "fromCache": true, "hasPendingWrites": false } ] } ] }, "Remote documents from watch are not GC'd": { "describeName": "Persistence:", "itName": "Remote documents from watch are not GC'd", "tags": [], "config": { "useGarbageCollection": false, "numClients": 1 }, "steps": [ { "userListen": [ 2, { "path": "collection", "filters": [], "orderBys": [] } ], "expectedState": { "activeTargets": { "2": { "queries": [ { "path": "collection", "filters": [], "orderBys": [] } ], "resumeToken": "" } } } }, { "watchAck": [ 2 ] }, { "watchEntity": { "docs": [ { "key": "collection/key", "version": 1000, "value": { "foo": "bar" }, "options": { "hasLocalMutations": false, "hasCommittedMutations": false } } ], "targets": [ 2 ] } }, { "watchCurrent": [ [ 2 ], "resume-token-1000" ] }, { "watchSnapshot": { "version": 1000, "targetIds": [] }, "expectedSnapshotEvents": [ { "query": { "path": "collection", "filters": [], "orderBys": [] }, "added": [ { "key": "collection/key", "version": 1000, "value": { "foo": "bar" }, "options": { "hasLocalMutations": false, "hasCommittedMutations": false } } ], "errorCode": 0, "fromCache": false, "hasPendingWrites": false } ] }, { "userUnlisten": [ 2, { "path": "collection", "filters": [], "orderBys": [] } ], "expectedState": { "activeTargets": {} } }, { "userListen": [ 2, { "path": "collection", "filters": [], "orderBys": [] } ], "expectedState": { "activeTargets": { "2": { "queries": [ { "path": "collection", "filters": [], "orderBys": [] } ], "resumeToken": "resume-token-1000" } } }, "expectedSnapshotEvents": [ { "query": { "path": "collection", "filters": [], "orderBys": [] }, "added": [ { "key": "collection/key", "version": 1000, "value": { "foo": "bar" }, "options": { "hasLocalMutations": false, "hasCommittedMutations": false } } ], "errorCode": 0, "fromCache": true, "hasPendingWrites": false } ] } ] }, "Remote documents from user sets are not GC'd": { "describeName": "Persistence:", "itName": "Remote documents from user sets are not GC'd", "tags": [], "config": { "useGarbageCollection": false, "numClients": 1 }, "steps": [ { "userSet": [ "collection/key", { "foo": "bar" } ] }, { "writeAck": { "version": 1000 }, "expectedState": { "userCallbacks": { "acknowledgedDocs": [ "collection/key" ], "rejectedDocs": [] } } }, { "userListen": [ 2, { "path": "collection", "filters": [], "orderBys": [] } ], "expectedState": { "activeTargets": { "2": { "queries": [ { "path": "collection", "filters": [], "orderBys": [] } ], "resumeToken": "" } } }, "expectedSnapshotEvents": [ { "query": { "path": "collection", "filters": [], "orderBys": [] }, "added": [ { "key": "collection/key", "version": 1000, "value": { "foo": "bar" }, "options": { "hasLocalMutations": false, "hasCommittedMutations": true } } ], "errorCode": 0, "fromCache": true, "hasPendingWrites": false } ] } ] }, "Mutation Queue is persisted across uid switches": { "describeName": "Persistence:", "itName": "Mutation Queue is persisted across uid switches", "tags": [], "config": { "useGarbageCollection": true, "numClients": 1 }, "steps": [ { "userSet": [ "users/anon", { "uid": "anon" } ] }, { "changeUser": "user1", "expectedState": { "numOutstandingWrites": 0 } }, { "userSet": [ "users/user1", { "uid": "user1" } ] }, { "userSet": [ "users/user1", { "uid": "user1", "extra": true } ] }, { "changeUser": null, "expectedState": { "numOutstandingWrites": 1 } }, { "writeAck": { "version": 1000 }, "expectedState": { "userCallbacks": { "acknowledgedDocs": [ "users/anon" ], "rejectedDocs": [] } } }, { "changeUser": "user1", "expectedState": { "numOutstandingWrites": 2 } }, { "writeAck": { "version": 2000 }, "expectedState": { "userCallbacks": { "acknowledgedDocs": [ "users/user1" ], "rejectedDocs": [] } } }, { "writeAck": { "version": 3000 }, "expectedState": { "userCallbacks": { "acknowledgedDocs": [ "users/user1" ], "rejectedDocs": [] } } } ] }, "Mutation Queue is persisted across uid switches (with restarts)": { "describeName": "Persistence:", "itName": "Mutation Queue is persisted across uid switches (with restarts)", "tags": [ "durable-persistence" ], "config": { "useGarbageCollection": true, "numClients": 1 }, "steps": [ { "userSet": [ "users/anon", { "uid": "anon" } ] }, { "changeUser": "user1", "expectedState": { "numOutstandingWrites": 0 } }, { "userSet": [ "users/user1", { "uid": "user1" } ] }, { "userSet": [ "users/user1", { "uid": "user1", "extra": true } ] }, { "changeUser": null }, { "restart": true, "expectedState": { "activeTargets": {}, "limboDocs": [], "numOutstandingWrites": 1 } }, { "writeAck": { "version": 1000 } }, { "changeUser": "user1" }, { "restart": true, "expectedState": { "activeTargets": {}, "limboDocs": [], "numOutstandingWrites": 2 } }, { "writeAck": { "version": 2000 } }, { "writeAck": { "version": 3000 } } ] }, "Visible mutations reflect uid switches": { "describeName": "Persistence:", "itName": "Visible mutations reflect uid switches", "tags": [], "config": { "useGarbageCollection": true, "numClients": 1 }, "steps": [ { "userListen": [ 2, { "path": "users", "filters": [], "orderBys": [] } ], "expectedState": { "activeTargets": { "2": { "queries": [ { "path": "users", "filters": [], "orderBys": [] } ], "resumeToken": "" } } } }, { "watchAck": [ 2 ] }, { "watchEntity": { "docs": [ { "key": "users/existing", "version": 0, "value": { "uid": "existing" }, "options": { "hasLocalMutations": false, "hasCommittedMutations": false } } ], "targets": [ 2 ] } }, { "watchCurrent": [ [ 2 ], "resume-token-500" ] }, { "watchSnapshot": { "version": 500, "targetIds": [] }, "expectedSnapshotEvents": [ { "query": { "path": "users", "filters": [], "orderBys": [] }, "added": [ { "key": "users/existing", "version": 0, "value": { "uid": "existing" }, "options": { "hasLocalMutations": false, "hasCommittedMutations": false } } ], "errorCode": 0, "fromCache": false, "hasPendingWrites": false } ] }, { "userSet": [ "users/anon", { "uid": "anon" } ], "expectedSnapshotEvents": [ { "query": { "path": "users", "filters": [], "orderBys": [] }, "added": [ { "key": "users/anon", "version": 0, "value": { "uid": "anon" }, "options": { "hasLocalMutations": true, "hasCommittedMutations": false } } ], "errorCode": 0, "fromCache": false, "hasPendingWrites": true } ] }, { "changeUser": "user1", "expectedState": { "activeTargets": { "2": { "queries": [ { "path": "users", "filters": [], "orderBys": [] } ], "resumeToken": "resume-token-500" } } }, "expectedSnapshotEvents": [ { "query": { "path": "users", "filters": [], "orderBys": [] }, "removed": [ { "key": "users/anon", "version": 0, "value": { "uid": "anon" }, "options": { "hasLocalMutations": true, "hasCommittedMutations": false } } ], "errorCode": 0, "fromCache": false, "hasPendingWrites": false } ] }, { "userSet": [ "users/user1", { "uid": "user1" } ], "expectedSnapshotEvents": [ { "query": { "path": "users", "filters": [], "orderBys": [] }, "added": [ { "key": "users/user1", "version": 0, "value": { "uid": "user1" }, "options": { "hasLocalMutations": true, "hasCommittedMutations": false } } ], "errorCode": 0, "fromCache": false, "hasPendingWrites": true } ] }, { "changeUser": null, "expectedSnapshotEvents": [ { "query": { "path": "users", "filters": [], "orderBys": [] }, "added": [ { "key": "users/anon", "version": 0, "value": { "uid": "anon" }, "options": { "hasLocalMutations": true, "hasCommittedMutations": false } } ], "removed": [ { "key": "users/user1", "version": 0, "value": { "uid": "user1" }, "options": { "hasLocalMutations": true, "hasCommittedMutations": false } } ], "errorCode": 0, "fromCache": false, "hasPendingWrites": true } ] } ] }, "Detects all active clients": { "describeName": "Persistence:", "itName": "Detects all active clients", "tags": [ "multi-client" ], "config": { "useGarbageCollection": false, "numClients": 2 }, "steps": [ { "drainQueue": true, "clientIndex": 0 }, { "applyClientState": { "visibility": "hidden" }, "expectedState": { "numActiveClients": 1 }, "clientIndex": 0 }, { "drainQueue": true, "clientIndex": 1 }, { "applyClientState": { "visibility": "visible" }, "expectedState": { "numActiveClients": 2 }, "clientIndex": 1 } ] }, "Single tab acquires primary lease": { "describeName": "Persistence:", "itName": "Single tab acquires primary lease", "tags": [ "multi-client" ], "config": { "useGarbageCollection": false, "numClients": 2 }, "steps": [ { "drainQueue": true, "clientIndex": 0 }, { "applyClientState": { "visibility": "hidden" }, "expectedState": { "isPrimary": true }, "clientIndex": 0 }, { "drainQueue": true, "clientIndex": 1 }, { "applyClientState": { "visibility": "hidden" }, "expectedState": { "isPrimary": false }, "clientIndex": 1 }, { "drainQueue": true, "clientIndex": 0 }, { "shutdown": true, "expectedState": { "activeTargets": {}, "limboDocs": [] }, "clientIndex": 0 }, { "drainQueue": true, "clientIndex": 1 }, { "runTimer": "client_metadata_refresh", "expectedState": { "isPrimary": true }, "clientIndex": 1 } ] }, "Foreground tab acquires primary lease": { "describeName": "Persistence:", "itName": "Foreground tab acquires primary lease", "tags": [ "multi-client" ], "config": { "useGarbageCollection": false, "numClients": 3 }, "steps": [ { "drainQueue": true, "clientIndex": 0 }, { "applyClientState": { "visibility": "hidden" }, "expectedState": { "isPrimary": true }, "clientIndex": 0 }, { "drainQueue": true, "clientIndex": 1 }, { "applyClientState": { "visibility": "hidden" }, "expectedState": { "isPrimary": false }, "clientIndex": 1 }, { "drainQueue": true, "clientIndex": 2 }, { "applyClientState": { "visibility": "visible" }, "expectedState": { "isPrimary": false }, "clientIndex": 2 }, { "drainQueue": true, "clientIndex": 0 }, { "shutdown": true, "expectedState": { "activeTargets": {}, "limboDocs": [] }, "clientIndex": 0 }, { "drainQueue": true, "clientIndex": 1 }, { "runTimer": "client_metadata_refresh", "expectedState": { "isPrimary": false }, "clientIndex": 1 }, { "drainQueue": true, "clientIndex": 2 }, { "runTimer": "client_metadata_refresh", "expectedState": { "isPrimary": true }, "clientIndex": 2 } ] }, "Primary lease bound to network state": { "describeName": "Persistence:", "itName": "Primary lease bound to network state", "tags": [ "multi-client" ], "config": { "useGarbageCollection": false, "numClients": 2 }, "steps": [ { "drainQueue": true, "expectedState": { "isPrimary": true }, "clientIndex": 0 }, { "enableNetwork": false, "expectedState": { "activeTargets": {}, "limboDocs": [], "isPrimary": true }, "clientIndex": 0 }, { "drainQueue": true, "expectedState": { "isPrimary": false }, "clientIndex": 1 }, { "drainQueue": true, "clientIndex": 0 }, { "runTimer": "client_metadata_refresh", "expectedState": { "isPrimary": false }, "clientIndex": 0 }, { "drainQueue": true, "clientIndex": 1 }, { "runTimer": "client_metadata_refresh", "expectedState": { "isPrimary": true }, "clientIndex": 1 }, { "enableNetwork": false, "expectedState": { "activeTargets": {}, "limboDocs": [], "isPrimary": true }, "clientIndex": 1 }, { "drainQueue": true, "clientIndex": 0 }, { "enableNetwork": true, "expectedState": { "isPrimary": false }, "clientIndex": 0 }, { "drainQueue": true, "clientIndex": 1 }, { "runTimer": "client_metadata_refresh", "expectedState": { "isPrimary": false }, "clientIndex": 1 }, { "drainQueue": true, "clientIndex": 0 }, { "runTimer": "client_metadata_refresh", "expectedState": { "isPrimary": true }, "clientIndex": 0 } ] }, "clearPersistence() shuts down other clients": { "describeName": "Persistence:", "itName": "clearPersistence() shuts down other clients", "tags": [ "multi-client" ], "config": { "useGarbageCollection": false, "numClients": 3 }, "steps": [ { "drainQueue": true, "clientIndex": 0 }, { "applyClientState": { "visibility": "visible" }, "clientIndex": 0 }, { "drainQueue": true, "clientIndex": 1 }, { "drainQueue": true, "clientIndex": 2 }, { "drainQueue": true, "clientIndex": 0 }, { "shutdown": true, "expectedState": { "activeTargets": {}, "limboDocs": [] }, "clientIndex": 0 }, { "clearPersistence": true, "clientIndex": 0 }, { "drainQueue": true, "expectedState": { "isShutdown": true }, "clientIndex": 1 }, { "drainQueue": true, "expectedState": { "isShutdown": true }, "clientIndex": 2 } ] } }