Bump google.golang.org/api
This commit is contained in:
67
vendor/cloud.google.com/go/pubsub/pullstream_test.go
generated
vendored
67
vendor/cloud.google.com/go/pubsub/pullstream_test.go
generated
vendored
@@ -15,11 +15,16 @@
|
||||
package pubsub
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
gax "github.com/googleapis/gax-go"
|
||||
"golang.org/x/net/context"
|
||||
"cloud.google.com/go/internal/testutil"
|
||||
"cloud.google.com/go/pubsub/pstest"
|
||||
gax "github.com/googleapis/gax-go/v2"
|
||||
"google.golang.org/api/option"
|
||||
pb "google.golang.org/genproto/googleapis/pubsub/v1"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -28,6 +33,7 @@ func TestPullStreamGet(t *testing.T) {
|
||||
// Test that we retry on the initial Send call from pullstream.get. We don't do this
|
||||
// test with the server in fake_test.go because there's no clear way to get Send
|
||||
// to fail from the server.
|
||||
t.Parallel()
|
||||
for _, test := range []struct {
|
||||
desc string
|
||||
errors []error
|
||||
@@ -61,7 +67,7 @@ func TestPullStreamGet(t *testing.T) {
|
||||
test.errors = test.errors[1:]
|
||||
return &testStreamingPullClient{sendError: err}, nil
|
||||
}
|
||||
ps := newPullStream(context.Background(), streamingPull, "", 0)
|
||||
ps := newPullStream(context.Background(), streamingPull, "")
|
||||
_, err := ps.get(nil)
|
||||
if got := status.Code(err); got != test.wantCode {
|
||||
t.Errorf("%s: got %s, want %s", test.desc, got, test.wantCode)
|
||||
@@ -69,6 +75,61 @@ func TestPullStreamGet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPullStreamGet_ResourceUnavailable(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
srv, err := testutil.NewServer()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer srv.Close()
|
||||
|
||||
ps := pstest.NewServer()
|
||||
defer ps.Close()
|
||||
|
||||
s := ExhaustedServer{ps.GServer}
|
||||
pb.RegisterPublisherServer(srv.Gsrv, &s)
|
||||
pb.RegisterSubscriberServer(srv.Gsrv, &s)
|
||||
srv.Start()
|
||||
|
||||
client, err := NewClient(ctx, "P",
|
||||
option.WithEndpoint(srv.Addr),
|
||||
option.WithoutAuthentication(),
|
||||
option.WithGRPCDialOption(grpc.WithInsecure()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
errc := make(chan error)
|
||||
go func() {
|
||||
errc <- client.Subscription("foo").Receive(ctx, func(context.Context, *Message) {
|
||||
t.Error("should not have received any data")
|
||||
})
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("Receive should have failed immediately")
|
||||
case err := <-errc:
|
||||
if gerr, ok := status.FromError(err); ok {
|
||||
if gerr.Code() != codes.ResourceExhausted {
|
||||
t.Fatal("expected to receive a grpc ResourceExhausted error")
|
||||
}
|
||||
} else {
|
||||
t.Fatal("expected to receive a grpc ResourceExhausted error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type ExhaustedServer struct {
|
||||
pstest.GServer
|
||||
}
|
||||
|
||||
func (*ExhaustedServer) StreamingPull(_ pb.Subscriber_StreamingPullServer) error {
|
||||
return status.Errorf(codes.ResourceExhausted, "This server is exhausted!")
|
||||
}
|
||||
|
||||
type testStreamingPullClient struct {
|
||||
pb.Subscriber_StreamingPullClient
|
||||
sendError error
|
||||
|
Reference in New Issue
Block a user