diff --git a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java index 1ce0dead8ea5..cc7624bb25d9 100644 --- a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java +++ b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java @@ -406,7 +406,6 @@ public void run() { Preconditions.checkState(stream == null); current = false; - hasPushed = false; nextAttempt = backoff.createNextAttempt(nextAttempt); stream = firestore.streamRequest(Watch.this, firestore.getClient().listenCallable()); diff --git a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/WatchTest.java b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/WatchTest.java index da6d6cd8d020..43b713312643 100644 --- a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/WatchTest.java +++ b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/WatchTest.java @@ -304,6 +304,35 @@ public void queryWatchReopensOnUnexceptedStreamEnd() throws InterruptedException awaitQuerySnapshot(new SnapshotDocument(ChangeType.ADDED, "coll/doc", SINGLE_FIELD_MAP)); } + @Test + public void queryWatchDoesntSendRaiseSnapshotOnReset() throws InterruptedException { + // This test is meant to reproduce https://github.com/googleapis/google-cloud-dotnet/issues/2542 + addQueryListener(); + + awaitAddTarget(); + + send(addTarget()); + send(current()); + send(snapshot()); + + awaitQuerySnapshot(); + + close(); + awaitClose(); + awaitAddTarget(); + + send(addTarget()); + send(current()); + // This should not raise a snapshot, since nothing has changed since the last snapshot. + send(snapshot()); + + send(doc("coll/doc", SINGLE_FIELD_PROTO)); + send(snapshot()); + + // Verify that we only receveived one snapshot. + awaitQuerySnapshot(new SnapshotDocument(ChangeType.ADDED, "coll/doc", SINGLE_FIELD_MAP)); + } + @Test public void queryWatchDoesntReopenInactiveStream() throws InterruptedException { addQueryListener();