{
  "Document remove message will cause docs to go in limbo": {
    "describeName": "Limbo Documents:",
    "itName": "Document remove message will cause docs to go in limbo",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 1001
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1002"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1002
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1001
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchEntity": {
          "key": "collection/b",
          "removedTargets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1003
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/b"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          1
        ]
      },
      {
        "watchCurrent": [
          [
            1
          ],
          "resume-token-1004"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1004
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1001
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Failed limbo resolution removes document from view": {
    "describeName": "Limbo Documents:",
    "itName": "Failed limbo resolution removes document from view",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
              [
                "matches",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "matches",
                      "==",
                      true
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "matches": true
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "matches": true
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "matches",
                  "==",
                  true
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userPatch": [
          "collection/a",
          {
            "modified": true
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "matches": true,
                  "modified": true
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
                [
                  "matches",
                  "==",
                  true
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
              [
                "matches",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userListen": [
          4,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "matches": true,
                  "modified": true
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            4
          ]
        }
      },
      {
        "watchCurrent": [
          [
            4
          ],
          "resume-token-1001"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1001
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 9
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "modified": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "matches": true
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/a"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          },
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a"
            ]
          }
        }
      },
      {
        "watchRemove": {
          "cause": {
            "code": 7
          },
          "targetIds": [
            1
          ]
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "matches": true
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Limbo docs are resolved by primary client": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo docs are resolved by primary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": [
          2,
          {
            "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": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 1001
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1002"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1002
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1001
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "key": "collection/b",
          "removedTargets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1003
        },
        "expectedState": {
          "activeLimboDocs": [
            "collection/b"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "watchAck": [
          1
        ]
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            1
          ],
          "resume-token-1004"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1004
        },
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1001
              }
            ]
          }
        ]
      }
    ]
  },
  "Limbo documents are deleted with an existence filter": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo documents are deleted with an existence filter",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "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": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchReset": [
          2
        ]
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1001"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1001
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/a"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          1
        ]
      },
      {
        "watchFilter": [
          [
            1
          ]
        ]
      },
      {
        "watchCurrent": [
          [
            1
          ],
          "resume-token-1002"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1002
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Limbo documents are deleted without an existence filter": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo documents are deleted without an existence filter",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "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": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchReset": [
          2
        ]
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1001"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1001
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/a"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          1
        ]
      },
      {
        "watchCurrent": [
          [
            1
          ],
          "resume-token-2"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1002
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Limbo documents are resolved after primary tab failover": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo documents are resolved after primary tab failover",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": [
          2,
          {
            "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": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 1001
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1001
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "key": "collection/b",
          "removedTargets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000000
        },
        "expectedState": {
          "activeLimboDocs": [
            "collection/b"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "shutdown": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "runTimer": "client_metadata_refresh",
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-3000000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000000
        },
        "expectedState": {
          "activeLimboDocs": [
            "collection/b"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000000"
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          1
        ]
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            1
          ],
          "resume-token-4000000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 4000000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1001
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000000"
            }
          }
        }
      }
    ]
  },
  "Limbo documents are resolved with updates": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo documents are resolved with updates",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
              [
                "key",
                "==",
                "a"
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "key",
                      "==",
                      "a"
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "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": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "key",
                  "==",
                  "a"
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchReset": [
          2
        ]
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1001"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1001
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "key",
                  "==",
                  "a"
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/a"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "key",
                      "==",
                      "a"
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          1
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 1002
            }
          ],
          "targets": [
            1
          ]
        }
      },
      {
        "watchCurrent": [
          [
            1
          ],
          "resume-token-1002"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1002
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "key",
                  "==",
                  "a"
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "key",
                      "==",
                      "a"
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Limbo documents are resolved with updates in different snapshot than \"current\"": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo documents are resolved with updates in different snapshot than \"current\"",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
              [
                "key",
                "==",
                "a"
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "key",
                      "==",
                      "a"
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "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": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "key",
                  "==",
                  "a"
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userListen": [
          4,
          {
            "filters": [
              [
                "key",
                "==",
                "b"
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "key",
                      "==",
                      "a"
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "key",
                      "==",
                      "b"
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchReset": [
          2
        ]
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1001"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1001
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "key",
                  "==",
                  "a"
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/a"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "key",
                      "==",
                      "a"
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "key",
                      "==",
                      "b"
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchAck": [
          1
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 1002
            }
          ],
          "targets": [
            1,
            4
          ]
        }
      },
      {
        "watchCurrent": [
          [
            4
          ],
          "resume-token-1002"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1002
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "key",
                  "==",
                  "a"
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ]
          },
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1002
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "key",
                  "==",
                  "b"
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                    [
                      "key",
                      "==",
                      "a"
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "key",
                      "==",
                      "b"
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchCurrent": [
          [
            1
          ],
          "resume-token-1003"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1003
        }
      }
    ]
  },
  "Limbo documents stay consistent between views": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo documents stay consistent between views",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "userSet": [
          "collection/a",
          {
            "matches": true
          }
        ]
      },
      {
        "userSet": [
          "collection/b",
          {
            "matches": true
          }
        ]
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "writeAck": {
          "version": 1001
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": true,
                  "hasLocalMutations": false
                },
                "value": {
                  "matches": true
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": true,
                  "hasLocalMutations": false
                },
                "value": {
                  "matches": true
                },
                "version": 1001
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "matches": true
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedState": {
          "activeLimboDocs": [
            "collection/b"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userListen": [
          4,
          {
            "filters": [
              [
                "matches",
                "==",
                true
              ]
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "matches": true
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": true,
                  "hasLocalMutations": false
                },
                "value": {
                  "matches": true
                },
                "version": 1001
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "matches",
                  "==",
                  true
                ]
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "matches",
                      "==",
                      true
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "matches",
                      "==",
                      true
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "matches": true
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": true,
                  "hasLocalMutations": false
                },
                "value": {
                  "matches": true
                },
                "version": 1001
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-2000"
            },
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "matches",
                      "==",
                      true
                    ]
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Limbo documents survive primary state transitions": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo documents survive primary state transitions",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 1001
            },
            {
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "c"
              },
              "version": 1002
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1001
              },
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "c"
                },
                "version": 1002
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "key": "collection/b",
          "removedTargets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "key": "collection/c",
          "removedTargets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/b",
            "collection/c"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "3": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/c"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 1,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "runTimer": "client_metadata_refresh",
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          },
          "isPrimary": false
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-3000000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000000
        },
        "expectedState": {
          "activeLimboDocs": [
            "collection/b",
            "collection/c"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000000"
            },
            "3": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/c"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          1
        ]
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            1
          ],
          "resume-token-3000000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000000
        },
        "expectedState": {
          "activeLimboDocs": [
            "collection/c"
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000000"
            },
            "3": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/c"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1001
              }
            ]
          }
        ]
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 0,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-5000000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 5000000
        },
        "expectedState": {
          "activeLimboDocs": [
            "collection/c"
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000000"
            },
            "5": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/c"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          5
        ]
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            5
          ],
          "resume-token-6000000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 6000000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "c"
                },
                "version": 1002
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000000"
            }
          }
        }
      }
    ]
  },
  "Limbo resolution handles snapshot before CURRENT": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo resolution handles snapshot before CURRENT",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "include": true,
                "key": "a"
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "include": true,
                "key": "b"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "include": true,
                  "key": "a"
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "include": true,
                  "key": "b"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userListen": [
          4,
          {
            "filters": [
              [
                "include",
                "==",
                true
              ]
            ],
            "limit": 1,
            "limitType": "LimitToFirst",
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "include": true,
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "include",
                  "==",
                  true
                ]
              ],
              "limit": 1,
              "limitType": "LimitToFirst",
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "include",
                      "==",
                      true
                    ]
                  ],
                  "limit": 1,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "include": true,
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            4
          ]
        }
      },
      {
        "watchCurrent": [
          [
            4
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "include",
                  "==",
                  true
                ]
              ],
              "limit": 1,
              "limitType": "LimitToFirst",
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userPatch": [
          "collection/a",
          {
            "include": false
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "include": true,
                  "key": "b"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "include",
                  "==",
                  true
                ]
              ],
              "limit": 1,
              "limitType": "LimitToFirst",
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "include": true,
                  "key": "a"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/b"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "include",
                      "==",
                      true
                    ]
                  ],
                  "limit": 1,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          1
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "include": true,
                "key": "b"
              },
              "version": 1000
            }
          ],
          "targets": [
            1
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "watchCurrent": [
          [
            1
          ],
          "resume-token-3000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "include": true,
                "key": "a"
              },
              "version": 1000
            }
          ],
          "removedTargets": [
            4
          ]
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "include": true,
                "key": "b"
              },
              "version": 1000
            }
          ],
          "targets": [
            4
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 4000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "include",
                  "==",
                  true
                ]
              ],
              "limit": 1,
              "limitType": "LimitToFirst",
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "include",
                      "==",
                      true
                    ]
                  ],
                  "limit": 1,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Limbo resolution handles snapshot before CURRENT [no document update]": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo resolution handles snapshot before CURRENT [no document update]",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "include": true,
                "key": "a"
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "include": true,
                "key": "b"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "include": true,
                  "key": "a"
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "include": true,
                  "key": "b"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userListen": [
          4,
          {
            "filters": [
              [
                "include",
                "==",
                true
              ]
            ],
            "limit": 1,
            "limitType": "LimitToFirst",
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "include": true,
                  "key": "a"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "include",
                  "==",
                  true
                ]
              ],
              "limit": 1,
              "limitType": "LimitToFirst",
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "include",
                      "==",
                      true
                    ]
                  ],
                  "limit": 1,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          4
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "include": true,
                "key": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            4
          ]
        }
      },
      {
        "watchCurrent": [
          [
            4
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "include",
                  "==",
                  true
                ]
              ],
              "limit": 1,
              "limitType": "LimitToFirst",
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userPatch": [
          "collection/a",
          {
            "include": false
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "include": true,
                  "key": "b"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "include",
                  "==",
                  true
                ]
              ],
              "limit": 1,
              "limitType": "LimitToFirst",
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "include": true,
                  "key": "a"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/b"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "include",
                      "==",
                      true
                    ]
                  ],
                  "limit": 1,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          1
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "watchCurrent": [
          [
            1
          ],
          "resume-token-3000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
                [
                  "include",
                  "==",
                  true
                ]
              ],
              "limit": 1,
              "limitType": "LimitToFirst",
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "include": true,
                  "key": "b"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                    [
                      "include",
                      "==",
                      true
                    ]
                  ],
                  "limit": 1,
                  "limitType": "LimitToFirst",
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "include": true,
                "key": "a"
              },
              "version": 1000
            }
          ],
          "removedTargets": [
            4
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 4000
        }
      }
    ]
  },
  "Limbo resolution throttling when a limbo listen is rejected.": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo resolution throttling when a limbo listen is rejected.",
    "tags": [
    ],
    "config": {
      "maxConcurrentLimboResolutions": 1,
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchReset": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1001"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/a"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
            "collection/b"
          ]
        }
      },
      {
        "watchRemove": {
          "cause": {
            "code": 8
          },
          "targetIds": [
            1
          ]
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/b"
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "3": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "watchRemove": {
          "cause": {
            "code": 8
          },
          "targetIds": [
            3
          ]
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
          ]
        }
      }
    ]
  },
  "Limbo resolution throttling with all results at once from watch": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo resolution throttling with all results at once from watch",
    "tags": [
    ],
    "config": {
      "maxConcurrentLimboResolutions": 2,
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 1000
            },
            {
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "c"
              },
              "version": 1000
            },
            {
              "key": "collection/d",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "d"
              },
              "version": 1000
            },
            {
              "key": "collection/e",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "e"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1000
              },
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "c"
                },
                "version": 1000
              },
              {
                "key": "collection/d",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "d"
                },
                "version": 1000
              },
              {
                "key": "collection/e",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "e"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchReset": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/a",
            "collection/b"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "3": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
            "collection/c",
            "collection/d",
            "collection/e"
          ]
        }
      },
      {
        "watchAck": [
          1
        ]
      },
      {
        "watchAck": [
          3
        ]
      },
      {
        "watchCurrent": [
          [
            1
          ],
          "resume-token-2001"
        ]
      },
      {
        "watchCurrent": [
          [
            3
          ],
          "resume-token-2001"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2001
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/c",
            "collection/d"
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "5": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/c"
                }
              ],
              "resumeToken": ""
            },
            "7": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/d"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
            "collection/e"
          ]
        }
      },
      {
        "watchAck": [
          5
        ]
      },
      {
        "watchAck": [
          7
        ]
      },
      {
        "watchCurrent": [
          [
            5
          ],
          "resume-token-2002"
        ]
      },
      {
        "watchCurrent": [
          [
            7
          ],
          "resume-token-2002"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2002
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "c"
                },
                "version": 1000
              },
              {
                "key": "collection/d",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "d"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/e"
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "9": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/e"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "watchAck": [
          9
        ]
      },
      {
        "watchCurrent": [
          [
            9
          ],
          "resume-token-2003"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2003
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/e",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "e"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
          ]
        }
      }
    ]
  },
  "Limbo resolution throttling with existence filter mismatch": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo resolution throttling with existence filter mismatch",
    "tags": [
    ],
    "config": {
      "maxConcurrentLimboResolutions": 2,
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a1",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a1"
              },
              "version": 1000
            },
            {
              "key": "collection/a2",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a2"
              },
              "version": 1000
            },
            {
              "key": "collection/a3",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a3"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a1",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a1"
                },
                "version": 1000
              },
              {
                "key": "collection/a2",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a2"
                },
                "version": 1000
              },
              {
                "key": "collection/a3",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a3"
                },
                "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"
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/b1",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b1"
              },
              "version": 1000
            },
            {
              "key": "collection/b2",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b2"
              },
              "version": 1000
            },
            {
              "key": "collection/b3",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b3"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchFilter": [
          [
            2
          ],
          "collection/b1",
          "collection/b2",
          "collection/b3"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1001
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/b1",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b1"
                },
                "version": 1000
              },
              {
                "key": "collection/b2",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b2"
                },
                "version": 1000
              },
              {
                "key": "collection/b3",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b3"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchRemove": {
          "targetIds": [
            2
          ]
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/b1",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b1"
              },
              "version": 1000
            },
            {
              "key": "collection/b2",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b2"
              },
              "version": 1000
            },
            {
              "key": "collection/b3",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b3"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1002"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1002
        },
        "expectedState": {
          "activeLimboDocs": [
            "collection/a1",
            "collection/a2"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a1"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "3": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a2"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
            "collection/a3"
          ]
        }
      },
      {
        "watchAck": [
          1
        ]
      },
      {
        "watchAck": [
          3
        ]
      },
      {
        "watchCurrent": [
          [
            1
          ],
          "resume-token-1003"
        ]
      },
      {
        "watchCurrent": [
          [
            3
          ],
          "resume-token-1003"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1003
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a1",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a1"
                },
                "version": 1000
              },
              {
                "key": "collection/a2",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a2"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/a3"
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "5": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a3"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "watchAck": [
          5
        ]
      },
      {
        "watchCurrent": [
          [
            5
          ],
          "resume-token-1004"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1004
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a3",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a3"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
          ]
        }
      }
    ]
  },
  "Limbo resolution throttling with results one at a time from watch": {
    "describeName": "Limbo Documents:",
    "itName": "Limbo resolution throttling with results one at a time from watch",
    "tags": [
    ],
    "config": {
      "maxConcurrentLimboResolutions": 2,
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "a"
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "b"
              },
              "version": 1000
            },
            {
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "c"
              },
              "version": 1000
            },
            {
              "key": "collection/d",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "d"
              },
              "version": 1000
            },
            {
              "key": "collection/e",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "key": "e"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1000
              },
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "c"
                },
                "version": 1000
              },
              {
                "key": "collection/d",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "d"
                },
                "version": 1000
              },
              {
                "key": "collection/e",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "e"
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchReset": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/a",
            "collection/b"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/a"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "3": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
            "collection/c",
            "collection/d",
            "collection/e"
          ]
        }
      },
      {
        "watchAck": [
          1
        ]
      },
      {
        "watchAck": [
          3
        ]
      },
      {
        "watchCurrent": [
          [
            1
          ],
          "resume-token-2001"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2001
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "a"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/b",
            "collection/c"
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "3": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/b"
                }
              ],
              "resumeToken": ""
            },
            "5": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/c"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
            "collection/d",
            "collection/e"
          ]
        }
      },
      {
        "watchAck": [
          5
        ]
      },
      {
        "watchCurrent": [
          [
            3
          ],
          "resume-token-2002"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2002
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "b"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/c",
            "collection/d"
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "5": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/c"
                }
              ],
              "resumeToken": ""
            },
            "7": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/d"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
            "collection/e"
          ]
        }
      },
      {
        "watchAck": [
          7
        ]
      },
      {
        "watchCurrent": [
          [
            5
          ],
          "resume-token-2003"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2003
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "c"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/d",
            "collection/e"
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "7": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/d"
                }
              ],
              "resumeToken": ""
            },
            "9": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/e"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "watchAck": [
          9
        ]
      },
      {
        "watchCurrent": [
          [
            7
          ],
          "resume-token-2004"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2004
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/d",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "d"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
            "collection/e"
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "9": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/e"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "watchCurrent": [
          [
            9
          ],
          "resume-token-2005"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2005
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/e",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "key": "e"
                },
                "version": 1000
              }
            ]
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          },
          "enqueuedLimboDocs": [
          ]
        }
      }
    ]
  },
  "LimitToLast query from secondary results in expected limbo doc": {
    "describeName": "Limbo Documents:",
    "itName": "LimitToLast query from secondary results in expected limbo doc",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": [
          2,
          {
            "filters": [
            ],
            "limit": 3,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 3,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 3,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 11
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 12
              },
              "version": 1000
            },
            {
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 13
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 13
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 12
                },
                "version": 1000
              },
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 11
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 3,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "watchReset": [
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 11
              },
              "version": 2000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 12
              },
              "version": 2000
            },
            {
              "key": "collection/d",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 100
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedState": {
          "activeLimboDocs": [
            "collection/c"
          ],
          "activeTargets": {
            "1": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/c"
                }
              ],
              "resumeToken": ""
            },
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 3,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 3,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "LimitToLast query from secondary results in no expected limbo doc": {
    "describeName": "Limbo Documents:",
    "itName": "LimitToLast query from secondary results in no expected limbo doc",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": [
          2,
          {
            "filters": [
            ],
            "limit": 3,
            "limitType": "LimitToLast",
            "orderBys": [
              [
                "val",
                "desc"
              ]
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 3,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 3,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 11
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 12
              },
              "version": 1000
            },
            {
              "key": "collection/c",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 13
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 13
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 12
                },
                "version": 1000
              },
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 11
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "limit": 3,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "watchReset": [
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 5
              },
              "version": 2000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 6
              },
              "version": 2000
            },
            {
              "key": "collection/d",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "val": 7
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/d",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 7
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "modified": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 6
                },
                "version": 2000
              },
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 5
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "limit": 3,
              "limitType": "LimitToLast",
              "orderBys": [
                [
                  "val",
                  "desc"
                ]
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "val": 13
                },
                "version": 1000
              }
            ]
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "limit": 3,
                  "limitType": "LimitToLast",
                  "orderBys": [
                    [
                      "val",
                      "desc"
                    ]
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  }
}
