From 0f3bc0efe58085957020033fc31c6a94e7df7a4e Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 4 Oct 2018 15:17:54 -0700 Subject: [PATCH] Don't raise empty Snapshots on resets (#3750) --- .../com/google/cloud/firestore/Watch.java | 1 - .../com/google/cloud/firestore/WatchTest.java | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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();