diff --git a/pkg/api/api/api_grpc_test.go b/pkg/api/api/api_grpc_test.go index 51e377d423..e9e1519696 100644 --- a/pkg/api/api/api_grpc_test.go +++ b/pkg/api/api/api_grpc_test.go @@ -2359,6 +2359,9 @@ func TestGrpcGetEvaluationsValidation(t *testing.T) { "authorization": []string{"test-key"}, }) actual, err := gs.GetEvaluations(ctx, p.input) + if p.expected != nil && actual != nil { + normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, actual.Evaluations) + } assert.Equal(t, p.expected, actual, "%s", p.desc) assert.Equal(t, p.expectedErr, err, "%s", p.desc) }) @@ -2410,6 +2413,7 @@ func TestGrpcGetEvaluationsZeroFeature(t *testing.T) { "authorization": []string{"test-key"}, }) actual, err := gs.GetEvaluations(ctx, p.input) + normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, actual.Evaluations) assert.Equal(t, p.expected, actual, "%s", p.desc) assert.Equal(t, p.expected.State, actual.State, "%s", p.desc) assert.Equal(t, p.expectedErr, err, "%s", p.desc) @@ -4959,6 +4963,18 @@ func emptyUserEvaluations(t *testing.T) *featureproto.UserEvaluations { } } +// CreatedAt is stamped by the service while the test runs, so it can differ from the value +// the expectation was built with and make a plain Equal flaky. Check it only loosely, then +// align expected with it so the remaining fields are still compared exactly. +func normalizeUserEvaluationsCreatedAt(t *testing.T, expected, actual *featureproto.UserEvaluations) { + t.Helper() + if expected == nil || actual == nil { + return + } + assert.InDelta(t, time.Now().Unix(), actual.CreatedAt, 5) + expected.CreatedAt = actual.CreatedAt +} + func TestGrpcListFeatures(t *testing.T) { t.Parallel() mockController := gomock.NewController(t) diff --git a/pkg/api/api/api_test.go b/pkg/api/api/api_test.go index 4de6a81bf3..656ba4d04e 100644 --- a/pkg/api/api/api_test.go +++ b/pkg/api/api/api_test.go @@ -716,7 +716,7 @@ func TestGetEvaluationsValidation(t *testing.T) { decoded := decodeSuccessResponse(t, actual.Body) err := json.Unmarshal(decoded, &respBody) assert.NoError(t, err) - // FIXME: This is a flaky test. CreateAt may not be equal ocasionally. + normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, respBody.Evaluations) assert.Equal(t, p.expected, &respBody, "%s", p.desc) } } @@ -779,6 +779,7 @@ func TestGetEvaluationsZeroFeature(t *testing.T) { decoded := decodeSuccessResponse(t, actual.Body) err := json.Unmarshal(decoded, &respBody) assert.NoError(t, err) + normalizeUserEvaluationsCreatedAt(t, p.expected.Evaluations, respBody.Evaluations) assert.Equal(t, p.expected, &respBody, "%s", p.desc) } }