{
  "Cache raises correct event if write is acked before watch delivers it": {
    "describeName": "Writes:",
    "itName": "Cache raises correct event if write is acked before watch delivers it",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/key",
          {
            "v": 2
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 2
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 2
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      }
    ]
  },
  "Cache will hold local write until watch catches up": {
    "describeName": "Writes:",
    "itName": "Cache will hold local write until watch catches up",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/key",
          {
            "v": 3
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 3
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 3000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 2
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "doc": "b"
              },
              "version": 3000
            },
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 3
              },
              "version": 3000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "doc": "b"
                },
                "version": 3000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 3
                },
                "version": 3000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Cache will not keep data for an outdated write ack": {
    "describeName": "Writes:",
    "itName": "Cache will not keep data for an outdated write ack",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/key",
          {
            "v": 2
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 3
              },
              "version": 10000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 10000
        }
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "modified": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 3
                },
                "version": 10000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Doesn't raise 'hasPendingWrites' for committed write and new listen": {
    "describeName": "Writes:",
    "itName": "Doesn't raise 'hasPendingWrites' for committed write and new listen",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "userSet": [
          "collection/doc",
          {
            "v": 1
          }
        ]
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/doc"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": true,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Doesn't raise event for document with pending patch": {
    "describeName": "Writes:",
    "itName": "Doesn't raise event for document with pending patch",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-250"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 250
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userPatch": [
          "collection/doc",
          {
            "v": 2
          }
        ]
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/doc"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/doc",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 500
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 500
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/doc",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 2
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 2
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Ensure correct events after patching a doc (including a delete) and getting watcher events.": {
    "describeName": "Writes:",
    "itName": "Ensure correct events after patching a doc (including a delete) and getting watcher events.",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/doc"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/doc"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/doc",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "a": {
                  "b": 2
                },
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-500"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 500
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "a": {
                    "b": 2
                  },
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/doc"
            }
          }
        ]
      },
      {
        "userPatch": [
          "collection/doc",
          {
            "a.c": "<DELETE>",
            "v": 2
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "a": {
                    "b": 2
                  },
                  "v": 2
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/doc"
            }
          }
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/doc",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "a": {
                  "b": 2
                },
                "v": 2
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "a": {
                    "b": 2
                  },
                  "v": 2
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/doc"
            }
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/doc"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Event is raised for a local set before and after the write ack": {
    "describeName": "Writes:",
    "itName": "Event is raised for a local set before and after the write ack",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/key",
          {
            "v": 2
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 2
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 2
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Failed writes are released immediately.": {
    "describeName": "Writes:",
    "itName": "Failed writes are released immediately.",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/b",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "userSet": [
          "collection/a",
          {
            "v": 2
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a"
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Local patch is applied to query until watch catches up": {
    "describeName": "Writes:",
    "itName": "Local patch is applied to query until watch catches up",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "userSet": [
          "collection/doc",
          {
            "local": 1
          }
        ]
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "local": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/doc"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/doc",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "local": 1,
                "remote": 2
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "modified": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "local": 1,
                  "remote": 2
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userPatch": [
          "collection/doc",
          {
            "local": 5
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "local": 5,
                  "remote": 2
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 5000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/doc"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/doc",
              "options": {
                "hasCommittedMutations": true,
                "hasLocalMutations": false
              },
              "value": {
                "local": 1,
                "remote": 3
              },
              "version": 3000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/doc",
              "options": {
                "hasCommittedMutations": true,
                "hasLocalMutations": false
              },
              "value": {
                "local": 1,
                "remote": 4
              },
              "version": 4000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 4000
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/doc",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "local": 5,
                "remote": 5
              },
              "version": 5000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 5000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "modified": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "local": 5,
                  "remote": 5
                },
                "version": 5000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Mutation are not sent twice after primary failover": {
    "describeName": "Writes:",
    "itName": "Mutation are not sent twice after primary failover",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "k": "a"
          }
        ]
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/b",
          {
            "k": "b"
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 1,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "writeAck": {
          "version": 1000
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 0,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": true,
                  "hasLocalMutations": false
                },
                "value": {
                  "k": "a"
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": true,
                  "hasLocalMutations": false
                },
                "value": {
                  "k": "b"
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Mutation recovers after primary takeover": {
    "describeName": "Writes:",
    "itName": "Mutation recovers after primary takeover",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "k": "a"
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "k": "a"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 1,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "writeAck": {
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "k": "a"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "k": "a"
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Mutations are scoped by user": {
    "describeName": "Writes:",
    "itName": "Mutations are scoped by user",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "changeUser": "user1",
        "clientIndex": 0
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "changeUser": "user2",
        "clientIndex": 1
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/b",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "New writes are sent after write failure": {
    "describeName": "Writes:",
    "itName": "New writes are sent after write failure",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 9
          }
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a"
            ]
          }
        }
      },
      {
        "userSet": [
          "collection/b",
          {
            "v": 1
          }
        ]
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Pending write is acknowledged by primary client": {
    "describeName": "Writes:",
    "itName": "Pending write is acknowledged by primary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-500"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 500
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 1000
        }
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Pending write is rejected by primary client": {
    "describeName": "Writes:",
    "itName": "Pending write is rejected by primary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-500"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 500
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "failWrite": {
          "error": {
            "code": 9
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a"
            ]
          }
        }
      }
    ]
  },
  "Pending writes are shared between clients": {
    "describeName": "Writes:",
    "itName": "Pending writes are shared between clients",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-500"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 500
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "v": 2
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 0
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 0
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/a",
          {
            "v": 3
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 3
                },
                "version": 0
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 3
                },
                "version": 0
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Pipelined writes can fail": {
    "describeName": "Writes:",
    "itName": "Pipelined writes can fail",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/a0",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a0",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a1",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a1",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a2",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a2",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a3",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a3",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a4",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a4",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a5",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a5",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a6",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a6",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a7",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a7",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a8",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a8",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a9",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a9",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a10",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a10",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a11",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a11",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a12",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a12",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a13",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a13",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a14",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a14",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "numOutstandingWrites": 10
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a0",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a0"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a1",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a1"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a2",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a2"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a3",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a3"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a4",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a4"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a5",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a5"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a6",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a6"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a7",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a7"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a8",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a8"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a9",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a9"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a10",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a10"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a11",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a11"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a12",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a12"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a13",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a13"
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a14",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "numOutstandingWrites": 0,
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a14"
            ]
          }
        }
      }
    ]
  },
  "Primary client acknowledges write": {
    "describeName": "Writes:",
    "itName": "Primary client acknowledges write",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Primary client rejects write": {
    "describeName": "Writes:",
    "itName": "Primary client rejects write",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "failWrite": {
          "error": {
            "code": 9
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/a"
            ]
          }
        }
      }
    ]
  },
  "Raises snapshot with 'hasPendingWrites' for unacknowledged write": {
    "describeName": "Writes:",
    "itName": "Raises snapshot with 'hasPendingWrites' for unacknowledged write",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "userSet": [
          "collection/doc",
          {
            "v": 1
          }
        ]
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Secondary tabs handle user change": {
    "describeName": "Writes:",
    "itName": "Secondary tabs handle user change",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "changeUser": "user1",
        "clientIndex": 0
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "changeUser": "user1",
        "clientIndex": 1
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/b",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "changeUser": "user2",
        "clientIndex": 0,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ]
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/c",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "changeUser": "user2",
        "clientIndex": 1,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ]
      },
      {
        "changeUser": "user1",
        "clientIndex": 1,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "changeUser": "user1",
        "clientIndex": 0,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            },
            "removed": [
              {
                "key": "collection/c",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ]
          }
        ]
      }
    ]
  },
  "Two sequential writes to different documents smoke test.": {
    "describeName": "Writes:",
    "itName": "Two sequential writes to different documents smoke test.",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 500
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 500
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a",
          {
            "v": 2
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 2
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        }
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 2
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "userSet": [
          "collection/b",
          {
            "v": 2
          }
        ],
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "modified": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 2
                },
                "version": 500
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 2
              },
              "version": 2500
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        }
      },
      {
        "writeAck": {
          "version": 2500
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 2
                },
                "version": 2500
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Unresponsive primary ignores acknowledged write": {
    "describeName": "Writes:",
    "itName": "Unresponsive primary ignores acknowledged write",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "k": "a"
          }
        ]
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/b",
          {
            "k": "b"
          }
        ]
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 2,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "keepInQueue": true,
          "version": 2000
        }
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "writeAck": {
          "version": 2000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Unresponsive primary ignores rejected write": {
    "describeName": "Writes:",
    "itName": "Unresponsive primary ignores rejected write",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "k": "a"
          }
        ]
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/b",
          {
            "k": "b"
          }
        ]
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 2,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "failWrite": {
          "error": {
            "code": 9
          },
          "keepInQueue": true
        }
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "failWrite": {
          "error": {
            "code": 9
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/b"
            ]
          }
        }
      }
    ]
  },
  "Wait for pending writes resolves after write acknowledgment": {
    "describeName": "Writes:",
    "itName": "Wait for pending writes resolves after write acknowledgment",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userSet": [
          "collection/a",
          {
            "k": "a"
          }
        ]
      },
      {
        "userSet": [
          "collection/b",
          {
            "k": "b"
          }
        ]
      },
      {
        "waitForPendingWrites": true
      },
      {
        "writeAck": {
          "version": 1001
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "failWrite": {
          "error": {
            "code": 9
          }
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/b"
            ]
          }
        },
        "expectedWaitForPendingWritesEvents": 1
      }
    ]
  },
  "Wait for pending writes resolves for write in secondary tab": {
    "describeName": "Writes:",
    "itName": "Wait for pending writes resolves for write in secondary tab",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/a",
          {
            "k": "a"
          }
        ]
      },
      {
        "clientIndex": 1,
        "waitForPendingWrites": true
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 1001
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        },
        "expectedWaitForPendingWritesEvents": 1
      }
    ]
  },
  "Wait for pending writes resolves if another write is issued": {
    "describeName": "Writes:",
    "itName": "Wait for pending writes resolves if another write is issued",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userSet": [
          "collection/a",
          {
            "k": "a"
          }
        ]
      },
      {
        "waitForPendingWrites": true
      },
      {
        "userSet": [
          "collection/b",
          {
            "k": "b"
          }
        ]
      },
      {
        "writeAck": {
          "version": 1001
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        },
        "expectedWaitForPendingWritesEvents": 1
      },
      {
        "writeAck": {
          "version": 1002
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Wait for pending writes resolves independently for different tabs": {
    "describeName": "Writes:",
    "itName": "Wait for pending writes resolves independently for different tabs",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "k": "a"
          }
        ]
      },
      {
        "clientIndex": 0,
        "waitForPendingWrites": true
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/b",
          {
            "k": "b"
          }
        ]
      },
      {
        "clientIndex": 1,
        "waitForPendingWrites": true
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "userSet": [
          "collection/c",
          {
            "k": "c"
          }
        ]
      },
      {
        "clientIndex": 2,
        "waitForPendingWrites": true
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 1001
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        },
        "expectedWaitForPendingWritesEvents": 1
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedWaitForPendingWritesEvents": 0
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedWaitForPendingWritesEvents": 0
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 1002
        },
        "expectedWaitForPendingWritesEvents": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        },
        "expectedWaitForPendingWritesEvents": 1
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedWaitForPendingWritesEvents": 0
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 1003
        },
        "expectedWaitForPendingWritesEvents": 0
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedWaitForPendingWritesEvents": 0
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/c"
            ],
            "rejectedDocs": [
            ]
          }
        },
        "expectedWaitForPendingWritesEvents": 1
      }
    ]
  },
  "Wait for pending writes resolves multiple times": {
    "describeName": "Writes:",
    "itName": "Wait for pending writes resolves multiple times",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userSet": [
          "collection/a",
          {
            "k": "a"
          }
        ]
      },
      {
        "waitForPendingWrites": true
      },
      {
        "waitForPendingWrites": true
      },
      {
        "writeAck": {
          "version": 1001
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        },
        "expectedWaitForPendingWritesEvents": 2
      }
    ]
  },
  "Wait for pending writes resolves with no writes": {
    "describeName": "Writes:",
    "itName": "Wait for pending writes resolves with no writes",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "waitForPendingWrites": true,
        "expectedWaitForPendingWritesEvents": 1
      }
    ]
  },
  "Wait for pending writes waits after restart": {
    "describeName": "Writes:",
    "itName": "Wait for pending writes waits after restart",
    "tags": [
      "durable-persistence"
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userSet": [
          "collection/a",
          {
            "k": "a"
          }
        ]
      },
      {
        "restart": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "waitForPendingWrites": true
      },
      {
        "writeAck": {
          "version": 1001
        },
        "expectedWaitForPendingWritesEvents": 1
      }
    ]
  },
  "Write are sequenced by multiple clients": {
    "describeName": "Writes:",
    "itName": "Write are sequenced by multiple clients",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 4,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/b",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "userSet": [
          "collection/c",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 3,
        "drainQueue": true
      },
      {
        "clientIndex": 3,
        "userSet": [
          "collection/d",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 2000
        }
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 3000
        }
      },
      {
        "clientIndex": 0,
        "failWrite": {
          "error": {
            "code": 9
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/c"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 3,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/d"
            ]
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/f",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/g",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 2,
        "drainQueue": true
      },
      {
        "clientIndex": 2,
        "userSet": [
          "collection/h",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 3,
        "drainQueue": true
      },
      {
        "clientIndex": 3,
        "userSet": [
          "collection/i",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 4000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/f"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 5000
        }
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 6000
        }
      },
      {
        "clientIndex": 0,
        "failWrite": {
          "error": {
            "code": 9
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/g"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/h"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 3,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/i"
            ]
          }
        }
      },
      {
        "clientIndex": 3,
        "drainQueue": true
      },
      {
        "clientIndex": 3,
        "userSet": [
          "collection/j",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 3,
        "userSet": [
          "collection/k",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 3,
        "userSet": [
          "collection/l",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 7000
        }
      },
      {
        "clientIndex": 0,
        "failWrite": {
          "error": {
            "code": 9
          }
        }
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 8000
        }
      },
      {
        "clientIndex": 3,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/j",
              "collection/l"
            ],
            "rejectedDocs": [
              "collection/k"
            ]
          }
        }
      }
    ]
  },
  "Write is executed after primary tab failover": {
    "describeName": "Writes:",
    "itName": "Write is executed after primary tab failover",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "visibility": "visible"
        },
        "clientIndex": 0,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": false
        }
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/b",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 1000
        }
      },
      {
        "clientIndex": 0,
        "shutdown": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 1,
        "runTimer": "client_metadata_refresh",
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Write is sent by newly started primary": {
    "describeName": "Writes:",
    "itName": "Write is sent by newly started primary",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 3,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": false
        }
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "shutdown": true,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ]
        }
      },
      {
        "clientIndex": 2,
        "drainQueue": true,
        "expectedState": {
          "isPrimary": true,
          "numOutstandingWrites": 1
        }
      },
      {
        "clientIndex": 2,
        "writeAck": {
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Writes are held during primary failover": {
    "describeName": "Writes:",
    "itName": "Writes are held during primary failover",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "userSet": [
          "collection/doc",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/doc"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "applyClientState": {
          "primary": true
        },
        "clientIndex": 1,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            }
          },
          "isPrimary": true
        }
      },
      {
        "clientIndex": 1,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/doc"
          },
          "targetId": 4
        },
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": true,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 2000
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/doc"
            }
          }
        ],
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-1000"
            },
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/doc"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 1,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 1,
        "watchAck": [
          4
        ]
      },
      {
        "clientIndex": 1,
        "watchEntity": {
          "docs": [
            {
              "key": "collection/doc",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 2000
            }
          ],
          "targets": [
            2,
            4
          ]
        }
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 1,
        "watchCurrent": [
          [
            4
          ],
          "resume-token-2000"
        ]
      },
      {
        "clientIndex": 1,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/doc"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            },
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/doc"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "runTimer": "client_metadata_refresh",
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/doc",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "isPrimary": false
        }
      }
    ]
  },
  "Writes are not re-sent after disable/enable network.": {
    "describeName": "Writes:",
    "itName": "Writes are not re-sent after disable/enable network.",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-500"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 500
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          },
          "writeStreamRequestCount": 2
        }
      },
      {
        "enableNetwork": false,
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ],
          "writeStreamRequestCount": 3
        }
      },
      {
        "enableNetwork": true,
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": "resume-token-500"
            }
          },
          "writeStreamRequestCount": 3
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-2000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Writes are not re-sent.": {
    "describeName": "Writes:",
    "itName": "Writes are not re-sent.",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-500"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 500
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "userSet": [
          "collection/b",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/b"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            },
            {
              "key": "collection/b",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              },
              {
                "key": "collection/b",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Writes are pipelined": {
    "describeName": "Writes:",
    "itName": "Writes are pipelined",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token"
        ]
      },
      {
        "userSet": [
          "collection/a0",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a0",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a1",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a1",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a2",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a2",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a3",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a3",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a4",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a4",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a5",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a5",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a6",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a6",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a7",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a7",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a8",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a8",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a9",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a9",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a10",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a10",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a11",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a11",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a12",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a12",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a13",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a13",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a14",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a14",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ],
        "expectedState": {
          "numOutstandingWrites": 10
        }
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a0"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a0",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a0",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 2000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a1"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a1",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 2000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a1",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 2000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 3000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a2"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a2",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 3000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 3000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a2",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 3000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 4000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a3"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a3",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 4000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 4000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a3",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 4000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 5000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a4"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a4",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 5000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 5000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a4",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 5000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 6000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a5"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a5",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 6000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 6000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a5",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 6000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 7000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a6"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a6",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 7000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 7000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a6",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 7000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 8000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a7"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a7",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 8000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 8000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a7",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 8000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 9000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a8"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a8",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 9000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 9000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a8",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 9000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 10000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a9"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a9",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 10000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 10000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a9",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 10000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 11000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a10"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a10",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 11000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 11000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a10",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 11000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 12000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a11"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a11",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 12000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 12000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a11",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 12000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 13000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a12"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a12",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 13000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 13000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a12",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 13000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 14000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a13"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a13",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 14000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 14000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "metadata": [
              {
                "key": "collection/a13",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 14000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 15000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a14"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a14",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 15000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 15000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/a14",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 15000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Writes are released by primary client": {
    "describeName": "Writes:",
    "itName": "Writes are released by primary client",
    "tags": [
      "multi-client"
    ],
    "config": {
      "numClients": 2,
      "useGarbageCollection": false
    },
    "steps": [
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "clientIndex": 0,
        "watchAck": [
          2
        ]
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchCurrent": [
          [
            2
          ],
          "resume-token-500"
        ]
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 500
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 1,
        "drainQueue": true
      },
      {
        "clientIndex": 1,
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ]
      },
      {
        "clientIndex": 0,
        "drainQueue": true,
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "clientIndex": 0,
        "writeAck": {
          "version": 1000
        }
      },
      {
        "clientIndex": 1,
        "drainQueue": true,
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "clientIndex": 0,
        "drainQueue": true
      },
      {
        "clientIndex": 0,
        "watchEntity": {
          "docs": [
            {
              "key": "collection/a",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "v": 1
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "clientIndex": 0,
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 2000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "v": 1
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      }
    ]
  },
  "Writes are released when there are no queries left": {
    "comment": "This test verifies that committed mutations are eligible for garbage collection on target removal",
    "describeName": "Writes:",
    "itName": "Writes are released when there are no queries left",
    "tags": [
      "eager-gc"
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-500"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 500
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "userSet": [
          "collection/a",
          {
            "v": 1
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/a",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "v": 1
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection"
            }
          }
        ]
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/a"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "userUnlisten": [
          2,
          {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          }
        ],
        "expectedState": {
          "activeTargets": {
          }
        }
      },
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection"
          },
          "targetId": 4
        },
        "expectedState": {
          "activeTargets": {
            "4": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      }
    ]
  },
  "Writes are resent after network disconnect": {
    "describeName": "Writes:",
    "itName": "Writes are resent after network disconnect",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedState": {
          "numOutstandingWrites": 1
        }
      },
      {
        "enableNetwork": false,
        "expectedState": {
          "activeLimboDocs": [
          ],
          "activeTargets": {
          },
          "enqueuedLimboDocs": [
          ],
          "writeStreamRequestCount": 3
        }
      },
      {
        "enableNetwork": true,
        "expectedState": {
          "numOutstandingWrites": 1,
          "writeStreamRequestCount": 5
        }
      },
      {
        "writeAck": {
          "version": 1
        },
        "expectedState": {
          "numOutstandingWrites": 0,
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      }
    ]
  },
  "Writes that fail with code aborted are retried": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code aborted are retried",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 10
          },
          "keepInQueue": true
        }
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "foo": "bar"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "foo": "bar"
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      }
    ]
  },
  "Writes that fail with code already-exists are rejected": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code already-exists are rejected",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 6
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            },
            "removed": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/key"
            ]
          }
        }
      }
    ]
  },
  "Writes that fail with code cancelled are retried": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code cancelled are retried",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 1
          },
          "keepInQueue": true
        }
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "foo": "bar"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "foo": "bar"
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      }
    ]
  },
  "Writes that fail with code data-loss are rejected": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code data-loss are rejected",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 15
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            },
            "removed": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/key"
            ]
          }
        }
      }
    ]
  },
  "Writes that fail with code deadline-exceeded are retried": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code deadline-exceeded are retried",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 4
          },
          "keepInQueue": true
        }
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "foo": "bar"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "foo": "bar"
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      }
    ]
  },
  "Writes that fail with code failed-precondition are rejected": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code failed-precondition are rejected",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 9
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            },
            "removed": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/key"
            ]
          }
        }
      }
    ]
  },
  "Writes that fail with code internal are retried": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code internal are retried",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 13
          },
          "keepInQueue": true
        }
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "foo": "bar"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "foo": "bar"
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      }
    ]
  },
  "Writes that fail with code invalid-argument are rejected": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code invalid-argument are rejected",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 3
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            },
            "removed": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/key"
            ]
          }
        }
      }
    ]
  },
  "Writes that fail with code not-found are rejected": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code not-found are rejected",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 5
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            },
            "removed": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/key"
            ]
          }
        }
      }
    ]
  },
  "Writes that fail with code out-of-range are rejected": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code out-of-range are rejected",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 11
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            },
            "removed": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/key"
            ]
          }
        }
      }
    ]
  },
  "Writes that fail with code permission-denied are rejected": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code permission-denied are rejected",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 7
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            },
            "removed": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/key"
            ]
          }
        }
      }
    ]
  },
  "Writes that fail with code resource_exhausted are not rejected": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code resource_exhausted are not rejected",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 8
          },
          "keepInQueue": true
        }
      }
    ]
  },
  "Writes that fail with code unauthenticated are retried": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code unauthenticated are retried",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 16
          },
          "keepInQueue": true
        }
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "foo": "bar"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "foo": "bar"
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      }
    ]
  },
  "Writes that fail with code unavailable are retried": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code unavailable are retried",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 14
          },
          "keepInQueue": true
        }
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "foo": "bar"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "foo": "bar"
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      }
    ]
  },
  "Writes that fail with code unimplemented are rejected": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code unimplemented are rejected",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 12
          }
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": false,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            },
            "removed": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ]
          }
        ],
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
            ],
            "rejectedDocs": [
              "collection/key"
            ]
          }
        }
      }
    ]
  },
  "Writes that fail with code unknown are retried": {
    "describeName": "Writes:",
    "itName": "Writes that fail with code unknown are retried",
    "tags": [
    ],
    "config": {
      "numClients": 1,
      "useGarbageCollection": true
    },
    "steps": [
      {
        "userListen": {
          "query": {
            "filters": [
            ],
            "orderBys": [
            ],
            "path": "collection/key"
          },
          "targetId": 2
        },
        "expectedState": {
          "activeTargets": {
            "2": {
              "queries": [
                {
                  "filters": [
                  ],
                  "orderBys": [
                  ],
                  "path": "collection/key"
                }
              ],
              "resumeToken": ""
            }
          }
        }
      },
      {
        "userSet": [
          "collection/key",
          {
            "foo": "bar"
          }
        ],
        "expectedSnapshotEvents": [
          {
            "added": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": true
                },
                "value": {
                  "foo": "bar"
                },
                "version": 0
              }
            ],
            "errorCode": 0,
            "fromCache": true,
            "hasPendingWrites": true,
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      },
      {
        "failWrite": {
          "error": {
            "code": 2
          },
          "keepInQueue": true
        }
      },
      {
        "writeAck": {
          "version": 1000
        },
        "expectedState": {
          "userCallbacks": {
            "acknowledgedDocs": [
              "collection/key"
            ],
            "rejectedDocs": [
            ]
          }
        }
      },
      {
        "watchAck": [
          2
        ]
      },
      {
        "watchEntity": {
          "docs": [
            {
              "key": "collection/key",
              "options": {
                "hasCommittedMutations": false,
                "hasLocalMutations": false
              },
              "value": {
                "foo": "bar"
              },
              "version": 1000
            }
          ],
          "targets": [
            2
          ]
        }
      },
      {
        "watchCurrent": [
          [
            2
          ],
          "resume-token-1000"
        ]
      },
      {
        "watchSnapshot": {
          "targetIds": [
          ],
          "version": 1000
        },
        "expectedSnapshotEvents": [
          {
            "errorCode": 0,
            "fromCache": false,
            "hasPendingWrites": false,
            "metadata": [
              {
                "key": "collection/key",
                "options": {
                  "hasCommittedMutations": false,
                  "hasLocalMutations": false
                },
                "value": {
                  "foo": "bar"
                },
                "version": 1000
              }
            ],
            "query": {
              "filters": [
              ],
              "orderBys": [
              ],
              "path": "collection/key"
            }
          }
        ]
      }
    ]
  }
}
