Skip to content
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

test: add more scheduler integration tests (2/) #539

Merged
merged 2 commits into from
Sep 27, 2023

Conversation

michaelawyu
Copy link
Contributor

Description of your changes

This PR features some more integration tests for the scheduler.

It also includes some minor fixes for the prev. PR that was not rebased into the branch in time.

I have:

  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

N/A

Special notes for your reviewer

if err := hubClient.Get(ctx, types.NamespacedName{Name: policySnapshotName}, policySnapshot); err != nil {
return err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

compare the full struct of the policy status?

If your function returns a struct, don't write test code that performs an individual comparison for each field of the struct. Instead, construct the struct that you're expecting your function to return, and compare in one shot using [diffs](https://github.com/golang/go/wiki/TestComments#print-diffs) or [deep comparisons](https://github.com/golang/go/wiki/TestComments#equality-comparison-and-diffs). The same rule applies to arrays and maps.
https://github.com/golang/go/wiki/TestComments#compare-full-structures

Copy link
Contributor Author

@michaelawyu michaelawyu Sep 26, 2023

Choose a reason for hiding this comment

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

Again and again, any Go guideline is just a general guideline, not a must. I don't particularly have a strong opinion on this one, but the check here is done separately to a) avoid having a large bloc of data and b) avoid stuffing the Diff() call with tons of options for sorting/ignoring nested fields, which is even more difficult to reason about.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can always construct the options using,

snapshotStatusCmpOptions = cmp.Options{
ignoreClusterDecisionReasonField,
cmpopts.SortSlices(lessFuncClusterDecision),
...
}

and build the wantStatus like

wantStatus := SchedulingPolicySnapshotStatus{
ObservedCRPGeneration: wantCRPGeneration
Conditions: []metav1.Condition{
wantScheduledCondition,
}
ClusterDecisions: wantClusterDecisions,
}

Then compare the status in one Diff call, the code will be cleaner than comparing the field one by one.
The amount of the data is the same as the current one.

Copy link
Contributor Author

@michaelawyu michaelawyu Sep 26, 2023

Choose a reason for hiding this comment

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

Stuffing all the options into one struct/array does not make them disappear -> it still targets a number of nested fields that is difficult to track. And building this want struct with blocks IMO does not help much with readability.

test/scheduler/utils_test.go Outdated Show resolved Hide resolved
test/scheduler/pickall_integration_test.go Outdated Show resolved Hide resolved
@michaelawyu michaelawyu merged commit beaac12 into Azure:main Sep 27, 2023
11 checks passed
@michaelawyu michaelawyu deleted the scheduler-integration-tests-2 branch September 27, 2023 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants