Skip to content

Commit 941987f

Browse files
t-kikucclaude
andauthored
fix(flaky test): use proto.Equal for gRPC status comparison in TestUpdateFeature (#2774)
* fix: use proto.Equal for gRPC status comparison in TestUpdateFeature The status error comparison used assert.Equal on serialized proto bytes, which is non-deterministic when ErrorInfo.Metadata has multiple map entries (messageKey + field). Switch to proto.Equal for semantic comparison. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: unpack Any details before proto.Equal comparison proto.Equal on Status.Proto() compares Any.value raw bytes, which still suffers from non-deterministic map serialization in ErrorInfo.Metadata. Instead, compare code/message individually and use Details() to unpack each Any into its concrete proto.Message before comparing with proto.Equal. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0da723d commit 941987f

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

pkg/feature/api/feature_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"google.golang.org/grpc/codes"
2727
"google.golang.org/grpc/metadata"
2828
"google.golang.org/grpc/status"
29+
"google.golang.org/protobuf/proto"
2930
"google.golang.org/protobuf/types/known/wrapperspb"
3031

3132
"github.com/bucketeer-io/bucketeer/v2/pkg/api/api"
@@ -3206,7 +3207,22 @@ func TestUpdateFeature(t *testing.T) {
32063207
p.setup(service)
32073208
}
32083209
_, err := service.UpdateFeature(p.ctx, p.input)
3209-
assert.Equal(t, p.expectedErr, err)
3210+
if p.expectedErr == nil {
3211+
assert.NoError(t, err)
3212+
} else {
3213+
require.Error(t, err)
3214+
expectedSt, _ := status.FromError(p.expectedErr)
3215+
actualSt, _ := status.FromError(err)
3216+
assert.Equal(t, expectedSt.Code(), actualSt.Code())
3217+
assert.Equal(t, expectedSt.Message(), actualSt.Message())
3218+
expectedDetails := expectedSt.Details()
3219+
actualDetails := actualSt.Details()
3220+
require.Equal(t, len(expectedDetails), len(actualDetails))
3221+
for i := range expectedDetails {
3222+
assert.True(t, proto.Equal(expectedDetails[i].(proto.Message), actualDetails[i].(proto.Message)),
3223+
"detail[%d]: expected %v, got %v", i, expectedDetails[i], actualDetails[i])
3224+
}
3225+
}
32103226
})
32113227
}
32123228
}

0 commit comments

Comments
 (0)