Skip to content

Commit

Permalink
Handle error testing with context cancels
Browse files Browse the repository at this point in the history
Fallback to allow context cancel errors if the server errors.
  • Loading branch information
emcfarlane committed Dec 29, 2023
1 parent e6323e0 commit 6e6e92b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions vanguard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,12 +893,10 @@ func runRPCTestCase[Client any](
}
var expectedErr *connect.Error
expectServerDone := true
var expectServerCancel bool
for _, streamMsg := range stream.msgs {
if streamMsg.in != nil && streamMsg.in.err != nil {
expectedErr = streamMsg.in.err
expectServerDone = false
expectServerCancel = true
break
}
if streamMsg.out != nil && streamMsg.out.err != nil {
Expand All @@ -919,10 +917,13 @@ func runRPCTestCase[Client any](
assert.Equal(t, receivedErr.Code(), connect.CodeOf(err))
}
// Also check the error observed by the server.
switch {
case expectedErr == nil:
if expectedErr == nil {

Check failure on line 920 in vanguard_test.go

View workflow job for this annotation

GitHub Actions / ci (1.21.x)

`if expectedErr == nil` has complex nested blocks (complexity: 5) (nestif)
assert.NoError(t, serverErr)
case expectServerCancel:
} else {
if serverErr == nil {
serverErr = err
}
assert.Error(t, serverErr)
if serverInvoked && serverErr != nil {
// We expect the server to either have seen the same error or it later
// observed a cancel error (since the middleware cancels the request
Expand All @@ -931,9 +932,6 @@ func runRPCTestCase[Client any](
assert.Equal(t, connect.CodeCanceled, connect.CodeOf(serverErr))
}
}
default:
assert.Error(t, serverErr)
assert.Equal(t, expectedErr.Code(), connect.CodeOf(serverErr))
}
assert.Subset(t, headers, stream.rspHeader)
if stream.err == nil {
Expand Down

0 comments on commit 6e6e92b

Please sign in to comment.