From fdc6c82f82f3c6dc861f805ab5dcc8abf342553f Mon Sep 17 00:00:00 2001 From: ptrus Date: Mon, 5 Oct 2020 11:46:28 +0200 Subject: [PATCH] go/e2e/queries: correctly ignore UnexpectedEOF errors --- .changelog/3372.internal.md | 1 + go/common/grpc/errors_test.go | 52 +++++++++++++++++++ .../cmd/debug/txsource/workload/queries.go | 7 ++- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 .changelog/3372.internal.md diff --git a/.changelog/3372.internal.md b/.changelog/3372.internal.md new file mode 100644 index 00000000000..b27dfe12003 --- /dev/null +++ b/.changelog/3372.internal.md @@ -0,0 +1 @@ +go/e2e/queries: correctly ignore UnexpectedEOF errors diff --git a/go/common/grpc/errors_test.go b/go/common/grpc/errors_test.go index f233ba47bf0..68741ce5459 100644 --- a/go/common/grpc/errors_test.go +++ b/go/common/grpc/errors_test.go @@ -2,12 +2,15 @@ package grpc import ( "context" + "io" "io/ioutil" "os" "testing" "github.com/stretchr/testify/require" "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "github.com/oasisprotocol/oasis-core/go/common/errors" ) @@ -22,6 +25,7 @@ type ErrorTestResponse struct { type ErrorTestService interface { ErrorTest(context.Context, *ErrorTestRequest) (*ErrorTestResponse, error) + ErrorStatusTest(context.Context, *ErrorTestRequest) (*ErrorTestResponse, error) } type errorTestServer struct { @@ -31,6 +35,10 @@ func (s *errorTestServer) ErrorTest(ctx context.Context, req *ErrorTestRequest) return &ErrorTestResponse{}, errTest } +func (s *errorTestServer) ErrorStatusTest(ctx context.Context, req *ErrorTestRequest) (*ErrorTestResponse, error) { + return nil, io.ErrUnexpectedEOF +} + type errorTestClient struct { cc *grpc.ClientConn } @@ -44,6 +52,15 @@ func (c *errorTestClient) ErrorTest(ctx context.Context, req *ErrorTestRequest) return rsp, nil } +func (c *errorTestClient) ErrorStatusTest(ctx context.Context, req *ErrorTestRequest) (*ErrorTestResponse, error) { + rsp := new(ErrorTestResponse) + err := c.cc.Invoke(ctx, "/ErrorTestService/ErrorStatusTest", req, rsp) + if err != nil { + return nil, err + } + return rsp, nil +} + var errorTestServiceDesc = grpc.ServiceDesc{ ServiceName: "ErrorTestService", HandlerType: (*ErrorTestService)(nil), @@ -52,6 +69,10 @@ var errorTestServiceDesc = grpc.ServiceDesc{ MethodName: "ErrorTest", Handler: handlerErrorTest, }, + { + MethodName: "ErrorStatusTest", + Handler: handlerErrorStatusTest, + }, }, Streams: []grpc.StreamDesc{}, } @@ -79,6 +100,29 @@ func handlerErrorTest( // nolint: golint return interceptor(ctx, req, info, handler) } +func handlerErrorStatusTest( // nolint: golint + srv interface{}, + ctx context.Context, + dec func(interface{}) error, + interceptor grpc.UnaryServerInterceptor, +) (interface{}, error) { + req := new(ErrorTestRequest) + if err := dec(req); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ErrorTestService).ErrorStatusTest(ctx, req) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ErrorTestService/ErrorStatusTest", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ErrorTestService).ErrorStatusTest(ctx, req.(*ErrorTestRequest)) + } + return interceptor(ctx, req, info, handler) +} + func TestErrorMapping(t *testing.T) { require := require.New(t) @@ -109,4 +153,12 @@ func TestErrorMapping(t *testing.T) { _, err = client.ErrorTest(context.Background(), &ErrorTestRequest{}) require.Error(err, "ErrorTest should return an error") require.Equal(err, errTest, "errors should be properly mapped") + + _, err = client.ErrorStatusTest(context.Background(), &ErrorTestRequest{}) + require.Error(err, "ErrorStatusTest should return an error") + require.True(IsErrorCode(err, codes.Unknown), "ErrorStatusTest should have code unknown") + st := GetErrorStatus(err) + require.NotNil(st, "GetErrorStatus should not be nil") + s, _ := status.FromError(io.ErrUnexpectedEOF) + require.EqualValues(s, st, "GetErrorStatus.Status should be io.ErrUnexpectedEOF") } diff --git a/go/oasis-node/cmd/debug/txsource/workload/queries.go b/go/oasis-node/cmd/debug/txsource/workload/queries.go index 3ce5c448813..e7d210633b5 100644 --- a/go/oasis-node/cmd/debug/txsource/workload/queries.go +++ b/go/oasis-node/cmd/debug/txsource/workload/queries.go @@ -12,6 +12,7 @@ import ( "github.com/spf13/viper" "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "github.com/oasisprotocol/oasis-core/go/common" "github.com/oasisprotocol/oasis-core/go/common/cbor" @@ -239,9 +240,11 @@ func (q *queries) doConsensusQueries(ctx context.Context, rng *rand.Rand, height "txs_with_results", txsWithRes, "height", height, "err", err, + "status", cmnGrpc.GetErrorStatus(err), ) - if status := cmnGrpc.GetErrorStatus(err); status != nil { - if status.Err() == io.ErrUnexpectedEOF { + if st := cmnGrpc.GetErrorStatus(err); st != nil { + s, _ := status.FromError(io.ErrUnexpectedEOF) + if st.Err().Error() == s.Err().Error() { // XXX: Connection seems to get occasionally reset with // FLOW_CONTROL_ERROR in GetTransactionsWithResult during // long-term tests, don't fail on this error until we