pubsub: fix flaky streaming retry test

When the stream of a streaming pull is closed by the server and there
is a client message in flight, the client message is lost. This caused
our streaming pull retry test to be flaky.

Fixed by adding a small delay to the server before returning an error.

Note that this is totally an artifact of our tests: at the end of the
interaction we compare what the server received with what it ideally
should have received.  With the actual service, dropped acks are a
real possibility.

Change-Id: I2e0af67d52371779d56ac6cd65b93d133bac3227
Reviewed-on: https://code-review.googlesource.com/11376
Reviewed-by: Michael Darakananda <pongad@google.com>
diff --git a/pubsub/fake_test.go b/pubsub/fake_test.go
index 9f7f0ef..2d444a8 100644
--- a/pubsub/fake_test.go
+++ b/pubsub/fake_test.go
@@ -21,6 +21,7 @@
 import (
 	"io"
 	"sync"
+	"time"
 
 	"golang.org/x/net/context"
 
@@ -113,6 +114,12 @@
 		}
 		pr := s.pullResponses[0]
 		s.pullResponses = s.pullResponses[1:]
+		if pr.err != nil {
+			// Add a slight delay to ensure the server receives any
+			// messages en route from the client before shutting down the stream.
+			// This reduces flakiness of tests involving retry.
+			time.Sleep(100 * time.Millisecond)
+		}
 		if pr.err == io.EOF {
 			return nil
 		}