-
Notifications
You must be signed in to change notification settings - Fork 4.5k
status: Fix status incompatibility introduced by #6919 and move non-regeneratable proto code into /testdata #7724
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
Changes from 4 commits
73e33f2
31d53ae
3b088a0
a0c3b84
25cf51e
8633ca3
7dd0e15
6009694
ecdbda8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,12 @@ go 1.22.7 | |
replace google.golang.org/grpc => ../../ | ||
|
||
require ( | ||
github.com/golang/protobuf v1.5.4 | ||
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. IIRC, the only reason this file was here is to hide this module dependency, since it's deprecated. Let's just delete this file now. I think we're going to have to accept a huge module dependency list, which is why I created #7690 - to make sure our actual production code dependencies can be tracked. 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. Removed the |
||
google.golang.org/grpc v1.66.2 | ||
google.golang.org/protobuf v1.34.2 | ||
) | ||
|
||
require ( | ||
github.com/golang/protobuf v1.5.4 // indirect | ||
golang.org/x/net v0.29.0 // indirect | ||
golang.org/x/sys v0.25.0 // indirect | ||
golang.org/x/text v0.18.0 // indirect | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,10 @@ import ( | |
"google.golang.org/grpc/status" | ||
"google.golang.org/protobuf/proto" | ||
"google.golang.org/protobuf/protoadapt" | ||
"google.golang.org/protobuf/testing/protocmp" | ||
|
||
testpb "google.golang.org/grpc/interop/grpc_testing" | ||
tpb "google.golang.org/grpc/testdata/grpc_testing_not_regenerate" | ||
) | ||
|
||
const defaultTestTimeout = 10 * time.Second | ||
|
@@ -203,3 +205,32 @@ func (s) TestStatusDetails(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
// TestStatus_ErrorDetailsMessageV1 verifies backward compatibility of the | ||
// status.Details() method when using protobuf code generated with only the | ||
// MessageV1 API implementation. | ||
func (s) TestStatus_ErrorDetailsMessageV1(t *testing.T) { | ||
details := []protoadapt.MessageV1{ | ||
&tpb.SimpleMessage{ | ||
Data: "abc", | ||
}, | ||
&testpb.Empty{}, | ||
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. According to the test comments, should 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. Yes, removed. I wanted to keep a test case for ensuring v1 + v2 messages are also handled correctly, added a new test function for that later. |
||
} | ||
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. Minor nit (optional) I feel this is more readable and compact: details := []protoadapt.MessageV1{
&tpb.SimpleMessage{Data: "abc"},
&testpb.Empty{},
} 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. Changed as suggested. |
||
s, err := status.New(codes.Aborted, "").WithDetails(details...) | ||
if err != nil { | ||
t.Fatalf("(%v).WithDetails(%+v) failed: %v", s, details, err) | ||
} | ||
got := s.Details() | ||
gotDetails := []protoadapt.MessageV1{} | ||
for i := range got { | ||
msg, ok := got[i].(protoadapt.MessageV1) | ||
if !ok { | ||
t.Fatalf("(%v).Details() returned message that doesn't implement protoadapt.MessageV1: %v", s, got[i]) | ||
} | ||
gotDetails = append(gotDetails, msg) | ||
} | ||
|
||
if diff := cmp.Diff(details, gotDetails, protocmp.Transform()); diff != "" { | ||
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 just have glance on 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. You're right, added a type comparison using |
||
t.Errorf("(%v).Details got unexpected output, diff (-got +want):\n%s", s, diff) | ||
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 order in the output, 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. Fixed. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2022 gRPC authors. | ||
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. Should this be 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. Fixed. |
||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
syntax = "proto3"; | ||
|
||
package grpc.testdata.grpc_testing_not_regenerate; | ||
|
||
option go_package = "google.golang.org/grpc/testdata/grpc_testing_not_regenerate"; | ||
|
||
// SimpleMessage is used to hold string data. | ||
message SimpleMessage { | ||
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 feel it is better to name the test message as 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 feel like "implementing the V1 API" is a property of the generated code and not the proto itself. There is a 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. Sorry I missed that. |
||
string data = 1; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Is this guaranteed to always be the case? (Does it matter?)
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.
I don't think so. The V1 API is deprecated and is only present for backward compatibility. There is no guarantee that
protoc-gen-go
will always support it.protoadapt.MessageV1Of
will return a wrapped message which implements the V1 API when the argument doesn't implement it already. Callers will need to unwrap it using theprotoadapt.MessageV2Of
to get the inner type.This is why I updated the doc comment to say the following:
status.WithDetails
accepts only V1 messages. To pass it a V2 message, it will need to be wrapped andstatus.Details()
will return the same wrapped type.