Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/api/api/api_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "%s", p.desc)
}
assert.Equal(t, p.expected, actual, "%s", p.desc)
assert.Equal(t, p.expectedErr, err, "%s", p.desc)
})
Expand Down Expand Up @@ -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, "%s", p.desc)
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)
Expand Down Expand Up @@ -4959,6 +4963,20 @@ func emptyUserEvaluations(t *testing.T) *featureproto.UserEvaluations {
}
}

// normalizeUserEvaluationsCreatedAt asserts CreatedAt is roughly now, then aligns expected so Equal stays stable.
func normalizeUserEvaluationsCreatedAt(
t *testing.T,
expected, actual *featureproto.UserEvaluations,
msgAndArgs ...interface{},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msgAndArgs can be dropped — t.Helper() already attributes the failure to the caller line, and the call sites run inside t.Run(p.desc) which names the case in the output.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t-kikuc
Modified to omit msgAndArgs.

) {
t.Helper()
if expected == nil || actual == nil {
return
}
assert.InDelta(t, time.Now().Unix(), actual.CreatedAt, 5, msgAndArgs...)
expected.CreatedAt = actual.CreatedAt
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment describes what the function does (readable from the signature + body). Replace with why — the flaky CreatedAt timing that motivates this helper.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t-kikuc
I have updated the description to address the instability (flaky behavior) regarding the timing of CreatedAt.


func TestGrpcListFeatures(t *testing.T) {
t.Parallel()
mockController := gomock.NewController(t)
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "%s", p.desc)
assert.Equal(t, p.expected, &respBody, "%s", p.desc)
}
}
Expand Down Expand Up @@ -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, "%s", p.desc)
assert.Equal(t, p.expected, &respBody, "%s", p.desc)
}
}
Expand Down
Loading