-
Notifications
You must be signed in to change notification settings - Fork 39
test(api): fix flaky GetEvaluations tests caused by CreatedAt #2792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| }) | ||
|
|
@@ -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) | ||
|
|
@@ -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{}, | ||
| ) { | ||
| t.Helper() | ||
| if expected == nil || actual == nil { | ||
| return | ||
| } | ||
| assert.InDelta(t, time.Now().Unix(), actual.CreatedAt, 5, msgAndArgs...) | ||
| expected.CreatedAt = actual.CreatedAt | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @t-kikuc |
||
|
|
||
| func TestGrpcListFeatures(t *testing.T) { | ||
| t.Parallel() | ||
| mockController := gomock.NewController(t) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msgAndArgscan be dropped —t.Helper()already attributes the failure to the caller line, and the call sites run insidet.Run(p.desc)which names the case in the output.There was a problem hiding this comment.
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.