{
  "Array-contains queries support resuming": {
    "describeName": "Listens:",
    "itName": "Array-contains queries support resuming",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
              [
                "array",
                "array-contains",
                42
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "array",
                      "array-contains",
                      42
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "array",
                  "array-contains",
                  42
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "array": [
                  1,
                  42,
                  3
                ],
                "foo": "bar"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "resumeToken": "resume-token-2000",
          "targetIds": [
            2
          ],
          "version": 2000
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "array": [
                    1,
                    42,
                    3
                  ],
                  "foo": "bar"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "array",
                  "array-contains",
                  42
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
              [
                "array",
                "array-contains",
                42
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
              [
                "array",
                "array-contains",
                42
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "array": [
                    1,
                    42,
                    3
                  ],
                  "foo": "bar"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "array",
                  "array-contains",
                  42
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "array",
                      "array-contains",
                      42
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-2000"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-3000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "array",
                  "array-contains",
                  42
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Can listen/unlisten to mirror queries.": {
    "describeName": "Listens:",
    "itName": "Can listen/unlisten to mirror queries.",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToFirst",
            "orderBys": [
              [
                "val",
                "asc"
              ]
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                },
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 0
              },
              "version": 1000
            },
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToFirst",
              "orderBys": [
                [
                  "val",
                  "asc"
                ]
              ],
              "path": "collection"
            }
          },
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 0
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToFirst",
              "orderBys": [
                [
                  "val",
                  "asc"
                ]
              ],
              "path": "collection"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              }
            ]
          }
        ]
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 2000
              },
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                },
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchRemove": {
          "cause": {
            "code": 8
          },
          "targetIds": [
            2
          ]
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 8,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToFirst",
              "orderBys": [
                [
                  "val",
                  "asc"
                ]
              ],
              "path": "collection"
            }
          },
          {
            "errorCode": 8,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      }
    ]
  },
  "Contents of query are cleared when listen is removed.": {
    "comment": "Explicitly tests eager GC behavior",
    "describeName": "Listens:",
    "itName": "Contents of query are cleared when listen is removed.",
    "tags": [
      "eager-gc"
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 4
        },
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Contents of query update when new data is received.": {
    "describeName": "Listens:",
    "itName": "Contents of query update when new data is received.",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Documents outside of view are cleared when listen is removed.": {
    "comment": "",
    "describeName": "Listens:",
    "itName": "Documents outside of view are cleared when listen is removed.",
    "tags": [
      "eager-gc"
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userSet": [
          "collection/a",
          {
            "matches": false
          }
        ]
      },
      {
        "userListen": {
          "query": {
            "filters": [
              [
                "matches",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "matches",
                      "==",
                      true
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "matches": true
              },
              "version": 1000
            },
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "matches": true
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "matches": true
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "matches",
                  "==",
                  true
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/b",
          {
            "matches": false
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "matches",
                  "==",
                  true
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "matches": true
                },
                "version": 1000
              }
            ]
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
              [
                "matches",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
              [
                "matches",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 4
        },
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "matches",
                      "==",
                      true
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userUnlisten": [
          4,
          {
            "filters": [
              [
                "matches",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "writeAck": {
          "version": 3000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 6
        },
        "expectedState": {
          "activeTargets": {
            "6": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userUnlisten": [
          6,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      }
    ]
  },
  "Does not raise event for initial document delete": {
    "describeName": "Listens:",
    "itName": "Does not raise event for initial document delete",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "value": null,
              "version": 1000
            }
          ],
          "removedTargets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Does not synthesize deletes for previously acked documents": {
    "describeName": "Listens:",
    "itName": "Does not synthesize deletes for previously acked documents",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/a"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/a"
            }
          }
        ]
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/a"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/a"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/a"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/a"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": "resume-token-2000"
            }
          }
        }
      }
    ]
  },
  "Doesn't include unknown documents in cached result": {
    "describeName": "Listens:",
    "itName": "Doesn't include unknown documents in cached result",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userSet": [
          "collection/exists",
          {
            "key": "a"
          }
        ]
      },
      {
        "userPatch": [
          "collection/unknown",
          {
            "key": "b"
          }
        ]
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/exists",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "key": "a"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Doesn't raise 'hasPendingWrites' for deletes": {
    "describeName": "Listens:",
    "itName": "Doesn't raise 'hasPendingWrites' for deletes",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userDelete": "collection/a",
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ]
          }
        ]
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "value": null,
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      }
    ]
  },
  "Doesn't raise events for empty target": {
    "describeName": "Listens:",
    "itName": "Doesn't raise events for empty target",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection1"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection1"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection2"
          },
          "targetId": 4
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection1"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection2"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection3"
          },
          "targetId": 6
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection1"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection2"
                }
              ],
              "resumeToken": ""
            },
            "6": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection3"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection2/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            4
          ]
        }
      },
      {
        "watchAck": [
          6
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection1"
            }
          },
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection2/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection2"
            }
          }
        ]
      }
    ]
  },
  "Empty initial snapshot is raised from cache": {
    "describeName": "Listens:",
    "itName": "Empty initial snapshot is raised from cache",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Empty initial snapshot is raised from cache in multiple tabs": {
    "describeName": "Listens:",
    "itName": "Empty initial snapshot is raised from cache in multiple tabs",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 0,
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Empty-due-to-delete initial snapshot is raised from cache": {
    "describeName": "Listens:",
    "itName": "Empty-due-to-delete initial snapshot is raised from cache",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userDelete": "collection/a"
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      }
    ]
  },
  "Empty-due-to-delete initial snapshot is raised from cache in multiple tabs": {
    "describeName": "Listens:",
    "itName": "Empty-due-to-delete initial snapshot is raised from cache in multiple tabs",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 0,
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "userDelete": "collection/a"
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "value": null,
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Ensure correct query results with latency-compensated deletes": {
    "describeName": "Listens:",
    "itName": "Ensure correct query results with latency-compensated deletes",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userDelete": "collection/b"
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "a": true
              },
              "version": 1000
            },
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "b": true
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "a": true
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "limit": 10,
            "limitType": "LimitToFirst",
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 4
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "a": true
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 10,
              "limitType": "LimitToFirst",
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 10,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "ExpectedCount in listen request should work after coming back online": {
    "describeName": "Listens:",
    "itName": "ExpectedCount in listen request should work after coming back online",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "enableNetwork": false,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "enableNetwork": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      }
    ]
  },
  "Ignores update from inactive target": {
    "describeName": "Listens:",
    "itName": "Ignores update from inactive target",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      }
    ]
  },
  "Individual (deleted) documents cannot revert": {
    "describeName": "Listens:",
    "itName": "Individual (deleted) documents cannot revert",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
              [
                "visible",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "visible",
                      "==",
                      true
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v1000",
                "visible": true
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v1000",
                  "visible": true
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "visible",
                  "==",
                  true
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
              [
                "visible",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 4
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v1000",
                  "visible": true
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "value": null,
              "version": 3000
            }
          ],
          "removedTargets": [
            4
          ]
        }
      },
      {
        "watchCurrent": [
          [
            4
          ],
          "resume-token-4000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 4000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v1000",
                  "visible": true
                },
                "version": 1000
              }
            ]
          }
        ]
      },
      {
        "userUnlisten": [
          4,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            4
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
              [
                "visible",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "visible",
                  "==",
                  true
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "visible",
                      "==",
                      true
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v2000",
                "visible": false
              },
              "version": 2000
            }
          ],
          "removedTargets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-5000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 5000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "visible",
                  "==",
                  true
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
              [
                "visible",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 4
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-4000"
            }
          }
        }
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            4
          ]
        }
      },
      {
        "watchCurrent": [
          [
            4
          ],
          "resume-token-6000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 6000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Individual documents cannot revert": {
    "describeName": "Listens:",
    "itName": "Individual documents cannot revert",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
              [
                "visible",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "visible",
                      "==",
                      true
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v1000",
                "visible": true
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v1000",
                  "visible": true
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "visible",
                  "==",
                  true
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
              [
                "visible",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 4
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v1000",
                  "visible": true
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v3000",
                "visible": false
              },
              "version": 3000
            }
          ],
          "targets": [
            4
          ]
        }
      },
      {
        "watchCurrent": [
          [
            4
          ],
          "resume-token-4000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 4000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "modified": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v3000",
                  "visible": false
                },
                "version": 3000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          4,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            4
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
              [
                "visible",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "visible",
                  "==",
                  true
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "visible",
                      "==",
                      true
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v2000",
                "visible": false
              },
              "version": 2000
            }
          ],
          "removedTargets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-5000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 5000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "visible",
                  "==",
                  true
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
              [
                "visible",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 4
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v3000",
                  "visible": false
                },
                "version": 3000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-4000"
            }
          }
        }
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            4
          ]
        }
      },
      {
        "watchCurrent": [
          [
            4
          ],
          "resume-token-6000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 6000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Listen is established in new primary tab": {
    "describeName": "Listens:",
    "itName": "Listen is established in new primary tab",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "shutdown": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "runTimer": "client_metadata_refresh",
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Listen is established in newly started primary": {
    "describeName": "Listens:",
    "itName": "Listen is established in newly started primary",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "shutdown": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 2,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 2,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 2,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 2,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Listen is re-listened to after primary tab failover": {
    "describeName": "Listens:",
    "itName": "Listen is re-listened to after primary tab failover",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "shutdown": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "runTimer": "client_metadata_refresh",
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Listens are reestablished after network disconnect": {
    "describeName": "Listens:",
    "itName": "Listens are reestablished after network disconnect",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          },
          "watchStreamRequestCount": 1
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "enableNetwork": false,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "enableNetwork": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          },
          "watchStreamRequestCount": 2
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Mirror queries from different secondary client": {
    "describeName": "Listens:",
    "itName": "Mirror queries from different secondary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToFirst",
            "orderBys": [
              [
                "val",
                "asc"
              ]
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "userListen": {
          "query": {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                },
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 0
              },
              "version": 1000
            },
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToFirst",
              "orderBys": [
                [
                  "val",
                  "asc"
                ]
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 2,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 0
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToFirst",
              "orderBys": [
                [
                  "val",
                  "asc"
                ]
              ],
              "path": "collection"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              }
            ]
          }
        ]
      }
    ]
  },
  "Mirror queries from primary and secondary client": {
    "describeName": "Listens:",
    "itName": "Mirror queries from primary and secondary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToFirst",
            "orderBys": [
              [
                "val",
                "asc"
              ]
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                },
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 0
              },
              "version": 1000
            },
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToFirst",
              "orderBys": [
                [
                  "val",
                  "asc"
                ]
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 0
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToFirst",
              "orderBys": [
                [
                  "val",
                  "asc"
                ]
              ],
              "path": "collection"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              }
            ]
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 2000
              },
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                },
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToFirst",
            "orderBys": [
              [
                "val",
                "asc"
              ]
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/d",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": -1
              },
              "version": 3000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/d",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": -1
                },
                "version": 3000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 2000
              }
            ]
          }
        ]
      },
      {
        "clientIndex": 1,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
          }
        }
      }
    ]
  },
  "Mirror queries from same secondary client": {
    "describeName": "Listens:",
    "itName": "Mirror queries from same secondary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToFirst",
            "orderBys": [
              [
                "val",
                "asc"
              ]
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                },
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                },
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                    [
                      "val",
                      "asc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 0
              },
              "version": 1000
            },
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToFirst",
              "orderBys": [
                [
                  "val",
                  "asc"
                ]
              ],
              "path": "collection"
            }
          },
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToFirst",
            "orderBys": [
              [
                "val",
                "asc"
              ]
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 2,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 0
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 0
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 2,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 1
                },
                "version": 1000
              }
            ]
          }
        ]
      },
      {
        "clientIndex": 1,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "limit": 2,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
          }
        }
      }
    ]
  },
  "New client becomes primary if no client has its network enabled": {
    "describeName": "Listens:",
    "itName": "New client becomes primary if no client has its network enabled",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "enableNetwork": false,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 2,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 2,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 2,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 2,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "New client uses existing online state": {
    "describeName": "Listens:",
    "itName": "New client uses existing online state",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "enableNetwork": false,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "enableNetwork": false,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 2,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Offline state doesn't persist if primary is shut down": {
    "describeName": "Listens:",
    "itName": "Offline state doesn't persist if primary is shut down",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "enableNetwork": false,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 0,
        "shutdown": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Omits global resume tokens for a short while": {
    "describeName": "Listens:",
    "itName": "Omits global resume tokens for a short while",
    "tags": [
      "durable-persistence"
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchSnapshot": {
          "resumeToken": "resume-token-2000",
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "restart": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-3000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Persists global resume tokens if the snapshot is old enough": {
    "describeName": "Listens:",
    "itName": "Persists global resume tokens if the snapshot is old enough",
    "tags": [
      "durable-persistence"
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchSnapshot": {
          "resumeToken": "resume-token-minutes-later",
          "targetIds": [
          ],
          "version": 300001000
        }
      },
      {
        "restart": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-minutes-later"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-even-later"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 300002000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Persists global resume tokens on unlisten": {
    "describeName": "Listens:",
    "itName": "Persists global resume tokens on unlisten",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchSnapshot": {
          "resumeToken": "resume-token-2000",
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-2000"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-3000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Persists resume token sent with target": {
    "describeName": "Listens:",
    "itName": "Persists resume token sent with target",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "resumeToken": "resume-token-2000",
          "targetIds": [
            2
          ],
          "version": 2000
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-2000"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-3000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Previous primary immediately regains primary lease": {
    "describeName": "Listens:",
    "itName": "Previous primary immediately regains primary lease",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 1,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "shutdown": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "runTimer": "client_metadata_refresh",
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-2000"
            }
          },
          "isPrimary": true
        }
      }
    ]
  },
  "Query bounces between primaries": {
    "describeName": "Listens:",
    "itName": "Query bounces between primaries",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 2,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "runTimer": "client_metadata_refresh",
        "expectedState": {
          "isPrimary": false
        }
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 2,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 2,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 2,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 1,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-2000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "c"
              },
              "version": 3000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-3000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "c"
                },
                "version": 3000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Query is executed by primary client": {
    "describeName": "Listens:",
    "itName": "Query is executed by primary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Query is joined by primary client": {
    "describeName": "Listens:",
    "itName": "Query is joined by primary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-100"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 100
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "c"
              },
              "version": 3000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "c"
                },
                "version": 3000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          },
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "c"
                },
                "version": 3000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Query is rejected and re-listened to": {
    "describeName": "Listens:",
    "itName": "Query is rejected and re-listened to",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchRemove": {
          "cause": {
            "code": 8
          },
          "targetIds": [
            2
          ]
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 8,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Query is rejected and re-listened to by secondary client": {
    "describeName": "Listens:",
    "itName": "Query is rejected and re-listened to by secondary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchRemove": {
          "cause": {
            "code": 8
          },
          "targetIds": [
            2
          ]
        },
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 8,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Query is rejected by primary client": {
    "describeName": "Listens:",
    "itName": "Query is rejected by primary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchRemove": {
          "cause": {
            "code": 8
          },
          "targetIds": [
            2
          ]
        },
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 8,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Query is resumed by secondary client": {
    "describeName": "Listens:",
    "itName": "Query is resumed by secondary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 0,
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Query is shared between primary and secondary client": {
    "describeName": "Listens:",
    "itName": "Query is shared between primary and secondary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Query is unlistened to by primary client": {
    "describeName": "Listens:",
    "itName": "Query is unlistened to by primary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
          }
        }
      }
    ]
  },
  "Query only raises events in participating clients": {
    "describeName": "Listens:",
    "itName": "Query only raises events in participating clients",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 4,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 3,
        "drainQueue": true
      },
      {
        "clientIndex": 3,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 3,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Query recovers after primary takeover": {
    "describeName": "Listens:",
    "itName": "Query recovers after primary takeover",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 1,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "c"
              },
              "version": 3000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "c"
                },
                "version": 3000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "runTimer": "client_metadata_refresh",
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 2000
              },
              {
                "createTime": 0,
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "c"
                },
                "version": 3000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "isPrimary": false
        }
      }
    ]
  },
  "Re-opens target without existence filter": {
    "describeName": "Listens:",
    "itName": "Re-opens target without existence filter",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "value": null,
              "version": 2000
            }
          ],
          "removedTargets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ]
          }
        ]
      }
    ]
  },
  "Resuming a query should specify expectedCount that does not include pending mutations": {
    "describeName": "Listens:",
    "itName": "Resuming a query should specify expectedCount that does not include pending mutations",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userSet": [
          "collection/b",
          {
            "key": "b"
          }
        ]
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "key": "b"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      }
    ]
  },
  "Resuming a query should specify expectedCount when adding the target": {
    "describeName": "Listens:",
    "itName": "Resuming a query should specify expectedCount when adding the target",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            },
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-2000"
            }
          }
        }
      }
    ]
  },
  "Secondary client advances query state with global snapshot from primary": {
    "describeName": "Listens:",
    "itName": "Secondary client advances query state with global snapshot from primary",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "1"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "1"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 0,
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "1"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "1"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1500"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1500
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userDelete": "collection/a"
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "1"
                },
                "version": 1000
              }
            ]
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "value": null,
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "key": "2"
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "key": "2"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Secondary client raises latency compensated snapshot from primary mutation": {
    "describeName": "Listens:",
    "itName": "Secondary client raises latency compensated snapshot from primary mutation",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "1"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "1"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "clientIndex": 0,
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "1"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "1"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1500"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1500
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "key": "2"
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "key": "2"
                },
                "version": 0
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Secondary client uses primary client's online state": {
    "describeName": "Listens:",
    "itName": "Secondary client uses primary client's online state",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "enableNetwork": false,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "enableNetwork": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Secondary client's online state is ignored": {
    "describeName": "Listens:",
    "itName": "Secondary client's online state is ignored",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "enableNetwork": false,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "enableNetwork": false,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ],
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "isPrimary": false
        }
      }
    ]
  },
  "Synthesizes deletes for missing document": {
    "describeName": "Listens:",
    "itName": "Synthesizes deletes for missing document",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            },
            {
              "createTime": 0,
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/a"
          },
          "targetId": 4
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/a"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchCurrent": [
          [
            4
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/a"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ]
          }
        ]
      },
      {
        "userUnlisten": [
          4,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/a"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            4
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      }
    ]
  },
  "Unresponsive primary ignores watch update": {
    "describeName": "Listens:",
    "itName": "Unresponsive primary ignores watch update",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 1,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Waits until Watch catches up to local deletes ": {
    "describeName": "Listens:",
    "itName": "Waits until Watch catches up to local deletes ",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "1"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "1"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userDelete": "collection/a",
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "1"
                },
                "version": 1000
              }
            ]
          }
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "2"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "writeAck": {
          "version": 4000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "3"
              },
              "version": 3000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "5"
              },
              "version": 5000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 5000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "5"
                },
                "version": 5000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Will gracefully handle watch stream reverting snapshots": {
    "describeName": "Listens:",
    "itName": "Will gracefully handle watch stream reverting snapshots",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v1000"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v1000"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v2000"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "modified": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v2000"
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v2000"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v1000"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v2000"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Will gracefully handle watch stream reverting snapshots (with restart)": {
    "describeName": "Listens:",
    "itName": "Will gracefully handle watch stream reverting snapshots (with restart)",
    "tags": [
      "durable-persistence"
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v1000"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v1000"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v2000"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "modified": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v2000"
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "restart": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": "v2000"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v1000"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": "v2000"
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Will gracefully process failed targets": {
    "describeName": "Listens:",
    "itName": "Will gracefully process failed targets",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection1"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection1"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection2"
          },
          "targetId": 4
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection1"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection2"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection1/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "a": true
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection2/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "b": true
              },
              "version": 1001
            }
          ],
          "targets": [
            4
          ]
        }
      },
      {
        "watchRemove": {
          "cause": {
            "code": 8
          },
          "targetIds": [
            2
          ]
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 8,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection1"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection2"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchCurrent": [
          [
            4
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection2/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "b": true
                },
                "version": 1001
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection2"
            }
          }
        ]
      }
    ]
  },
  "Will process removals without waiting for a consistent snapshot": {
    "describeName": "Listens:",
    "itName": "Will process removals without waiting for a consistent snapshot",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchRemove": {
          "cause": {
            "code": 8
          },
          "targetIds": [
            2
          ]
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 8,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      }
    ]
  },
  "Will re-issue listen for errored target": {
    "describeName": "Listens:",
    "itName": "Will re-issue listen for errored target",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchRemove": {
          "cause": {
            "code": 8
          },
          "targetIds": [
            2
          ]
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 8,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "onSnapshotsInSync fires for metadata changes": {
    "describeName": "Listens:",
    "itName": "onSnapshotsInSync fires for metadata changes",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "addSnapshotsInSyncListener": true,
        "expectedSnapshotsInSyncEvents": 1
      },
      {
        "userSet": [
          "collection/a",
          {
            "v": 2
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 0
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedSnapshotsInSyncEvents": 1
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 2
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 2
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedSnapshotsInSyncEvents": 1,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "onSnapshotsInSync fires for multiple listeners": {
    "describeName": "Listens:",
    "itName": "onSnapshotsInSync fires for multiple listeners",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "addSnapshotsInSyncListener": true,
        "expectedSnapshotsInSyncEvents": 1
      },
      {
        "userSet": [
          "collection/a",
          {
            "v": 2
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 0
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedSnapshotsInSyncEvents": 1
      },
      {
        "addSnapshotsInSyncListener": true,
        "expectedSnapshotsInSyncEvents": 1
      },
      {
        "addSnapshotsInSyncListener": true,
        "expectedSnapshotsInSyncEvents": 1
      },
      {
        "userSet": [
          "collection/a",
          {
            "v": 3
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 3
                },
                "version": 0
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedSnapshotsInSyncEvents": 3
      },
      {
        "removeSnapshotsInSyncListener": true
      },
      {
        "userSet": [
          "collection/a",
          {
            "v": 4
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 4
                },
                "version": 0
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedSnapshotsInSyncEvents": 2
      }
    ]
  },
  "onSnapshotsInSync fires once for multiple event snapshots": {
    "describeName": "Listens:",
    "itName": "onSnapshotsInSync fires once for multiple event snapshots",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/a"
          },
          "targetId": 4
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/a"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            4
          ]
        }
      },
      {
        "watchCurrent": [
          [
            4
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/a"
            }
          }
        ]
      },
      {
        "addSnapshotsInSyncListener": true,
        "expectedSnapshotsInSyncEvents": 1
      },
      {
        "userSet": [
          "collection/a",
          {
            "v": 2
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 0
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          },
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 0
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/a"
            }
          }
        ],
        "expectedSnapshotsInSyncEvents": 1
      },
      {
        "watchEntity": {
          "docs": [
            {
              "createTime": 0,
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 2
              },
              "version": 2000
            }
          ],
          "targets": [
            2,
            4
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 2
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          },
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "createTime": 0,
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 2
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/a"
            }
          }
        ],
        "expectedSnapshotsInSyncEvents": 1,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "onSnapshotsInSync fires when called even if there are no local listeners": {
    "describeName": "Listens:",
    "itName": "onSnapshotsInSync fires when called even if there are no local listeners",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "addSnapshotsInSyncListener": true,
        "expectedSnapshotsInSyncEvents": 1
      },
      {
        "addSnapshotsInSyncListener": true,
        "expectedSnapshotsInSyncEvents": 1
      }
    ]
  },
  "onSnapshotsInSync should not fire for doc changes if there are no listeners": {
    "describeName": "Listens:",
    "itName": "onSnapshotsInSync should not fire for doc changes if there are no listeners",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useEagerGCForMemory": true
    },
    "steps": [
      {
        "addSnapshotsInSyncListener": true,
        "expectedSnapshotsInSyncEvents": 1
      },
      {
        "userSet": [
          "collection/a",
          {
            "v": 2
          }
        ]
      }
    ]
  }
}
