-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Firestore and held-back dependencies #21190
Changes from all commits
a71e76c
0da374f
fa84634
d64a515
5f52d7e
e3e4310
104f702
09c7f36
3a5acf2
ef212f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,23 +20,25 @@ import ( | |||||
"fmt" | ||||||
"net" | ||||||
"os" | ||||||
"reflect" | ||||||
"strings" | ||||||
"testing" | ||||||
"time" | ||||||
"unsafe" | ||||||
|
||||||
"cloud.google.com/go/firestore" | ||||||
"cloud.google.com/go/firestore/apiv1/admin/adminpb" | ||||||
"cloud.google.com/go/firestore/apiv1/firestorepb" | ||||||
"github.com/gravitational/trace" | ||||||
"github.com/jonboulle/clockwork" | ||||||
"github.com/sirupsen/logrus" | ||||||
"github.com/stretchr/testify/require" | ||||||
"google.golang.org/api/option" | ||||||
adminpb "google.golang.org/genproto/googleapis/firestore/admin/v1" | ||||||
firestorepb "google.golang.org/genproto/googleapis/firestore/v1" | ||||||
"google.golang.org/genproto/googleapis/rpc/code" | ||||||
"google.golang.org/genproto/googleapis/rpc/status" | ||||||
"google.golang.org/grpc" | ||||||
"google.golang.org/grpc/codes" | ||||||
"google.golang.org/grpc/credentials/insecure" | ||||||
"google.golang.org/grpc/metadata" | ||||||
"google.golang.org/grpc/status" | ||||||
"google.golang.org/protobuf/proto" | ||||||
"google.golang.org/protobuf/types/known/timestamppb" | ||||||
|
||||||
|
@@ -194,25 +196,29 @@ type mockFirestoreServer struct { | |||||
commitErr error | ||||||
} | ||||||
|
||||||
func (s *mockFirestoreServer) Commit(ctx context.Context, req *firestorepb.CommitRequest) (*firestorepb.CommitResponse, error) { | ||||||
func (s *mockFirestoreServer) BatchWrite(ctx context.Context, req *firestorepb.BatchWriteRequest) (*firestorepb.BatchWriteResponse, error) { | ||||||
md, _ := metadata.FromIncomingContext(ctx) | ||||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") { | ||||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg) | ||||||
} | ||||||
|
||||||
if len(req.Writes) > commitLimit { | ||||||
return nil, status.Errorf(codes.InvalidArgument, "too many writes in a transaction") | ||||||
} | ||||||
|
||||||
s.reqs = append(s.reqs, req) | ||||||
if s.commitErr != nil { | ||||||
return nil, s.commitErr | ||||||
} | ||||||
return &firestorepb.CommitResponse{ | ||||||
WriteResults: []*firestorepb.WriteResult{{ | ||||||
|
||||||
resp := &firestorepb.BatchWriteResponse{} | ||||||
for i := 0; i < len(req.Writes); i++ { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: If you don't need the variable:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even better ☝️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hold up, when did we get this syntax? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since forever, I think. |
||||||
resp.Status = append(resp.Status, &status.Status{ | ||||||
Code: int32(code.Code_OK), | ||||||
}) | ||||||
|
||||||
resp.WriteResults = append(resp.WriteResults, &firestorepb.WriteResult{ | ||||||
UpdateTime: timestamppb.Now(), | ||||||
}}, | ||||||
}, nil | ||||||
}) | ||||||
} | ||||||
|
||||||
return resp, nil | ||||||
} | ||||||
|
||||||
func TestDeleteDocuments(t *testing.T) { | ||||||
|
@@ -231,19 +237,9 @@ func TestDeleteDocuments(t *testing.T) { | |||||
documents: 1, | ||||||
}, | ||||||
{ | ||||||
name: "commit less than limit", | ||||||
name: "commit success", | ||||||
assertion: require.NoError, | ||||||
documents: commitLimit - 123, | ||||||
}, | ||||||
{ | ||||||
name: "commit limit", | ||||||
assertion: require.NoError, | ||||||
documents: commitLimit, | ||||||
}, | ||||||
{ | ||||||
name: "commit more than limit", | ||||||
assertion: require.NoError, | ||||||
documents: (commitLimit * 3) + 173, | ||||||
documents: 1796, | ||||||
}, | ||||||
} | ||||||
|
||||||
|
@@ -261,6 +257,14 @@ func TestDeleteDocuments(t *testing.T) { | |||||
CreateTime: time.Now(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Use for-range above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment is still viable, although certainly not worth a PR. |
||||||
UpdateTime: time.Now(), | ||||||
}) | ||||||
|
||||||
// We really shouldn't need this, but the Firestore SDK made some unfortunate design | ||||||
// decisions that make it impossible to set the field of a DocumentRef used for the seemingly | ||||||
// useless deduplication in the BulkWriter API. | ||||||
rs := reflect.ValueOf(docs[i].Ref).Elem() | ||||||
rf := rs.FieldByName("shortPath") | ||||||
rf = reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem() | ||||||
rf.SetString(docs[i].Ref.Path) | ||||||
Comment on lines
+261
to
+267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the consequence of not setting this? Could we get around the reflect block in some other way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was already merged due to @rosstimothy adding it to the queue. I was confused by errors for some time in tests for quite some time that didn't crop up in real world testing. As it turns out, the firestore SDK This would be fine, the test generates an unique There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could not find an alternative way around this easily. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough, thanks for the explanation. |
||||||
} | ||||||
|
||||||
mockFirestore := &mockFirestoreServer{ | ||||||
|
@@ -310,7 +314,7 @@ func TestDeleteDocuments(t *testing.T) { | |||||
var committed int | ||||||
for _, req := range mockFirestore.reqs { | ||||||
switch r := req.(type) { | ||||||
case *firestorepb.CommitRequest: | ||||||
case *firestorepb.BatchWriteRequest: | ||||||
committed += len(r.Writes) | ||||||
} | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update api/go.mod too.