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

chore: fix multirm unit test flake #8949

Merged
merged 3 commits into from
Mar 5, 2024

Conversation

carolinaecalderon
Copy link
Contributor

Description

require error.Contains for multiRM unit test that returns a list of resource managers. This way, we'll avoid failing the test if the list is a different order.

Test Plan

Pass test

Commentary (optional)

Checklist

  • Changes have been manually QA'd
  • User-facing API changes need the "User-facing API Change" label.
  • Release notes should be added as a separate file under docs/release-notes/.
    See Release Note for details.
  • Licenses should be included for new code which was copied and/or modified from any external code.

Ticket

@cla-bot cla-bot bot added the cla-signed label Mar 4, 2024
@carolinaecalderon carolinaecalderon marked this pull request as ready for review March 4, 2024 22:02
@carolinaecalderon carolinaecalderon requested a review from a team as a code owner March 4, 2024 22:02
Copy link

netlify bot commented Mar 4, 2024

Deploy Preview for determined-ui canceled.

Name Link
🔨 Latest commit 8fac172
🔍 Latest deploy log https://app.netlify.com/sites/determined-ui/deploys/65e736dc3b3fee0008f9ea1e

Copy link

codecov bot commented Mar 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 47.27%. Comparing base (a5b425a) to head (8fac172).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8949   +/-   ##
=======================================
  Coverage   47.27%   47.27%           
=======================================
  Files        1162     1162           
  Lines      176114   176115    +1     
  Branches     2235     2237    +2     
=======================================
+ Hits        83259    83260    +1     
  Misses      92697    92697           
  Partials      158      158           
Flag Coverage Δ
backend 42.34% <100.00%> (-0.01%) ⬇️
harness 63.95% <ø> (+<0.01%) ⬆️
web 42.53% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
master/internal/rm/multirm/multirm.go 86.26% <100.00%> (+0.07%) ⬆️

... and 3 files with indirect coverage changes

// Manually checking for ErrRMConflict because RMs may be returned in different order.
require.ErrorContains(t, err, "exists for both resource managers")
require.ErrorContains(t, err, "aws")
require.ErrorContains(t, err, "gcp")
Copy link
Contributor

Choose a reason for hiding this comment

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

weird to hard code it this way to me. should it just use parameters in the test case instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could introduce an extra parameter to use just in this case.
is that preferable? even if the other 7/8 cases won't need it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pushed a new commit to add the extra param, lmk if you'd rather I revert

}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
rmName, err := mockMultiRM.getRM(tt.rmName, tt.rpName)
require.Equal(t, tt.expectedRMName, rmName)
require.Equal(t, tt.err, err)
if tt.err != nil && strings.Contains(tt.err.Error(), "exists for both resource managers") {
require.ErrorContains(t, err, "exists for both resource managers")
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good to check error string length here too, to make sure the conflict checking behavior doesn't miss or over-count one.

Suggested change
require.ErrorContains(t, err, "exists for both resource managers")
require.ErrorContains(t, err, "exists for both resource managers")
require.Equal(t, len(tt.err.Error()), len(err.Error())

@@ -719,21 +720,33 @@ func TestGetRMName(t *testing.T) {
rpName string
err error
expectedRMName string
rmConflicts []string
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a different take on this.

Let's just sort rmNames here

return fmt.Errorf("resource pool %s exists for both resource managers %v,", rp, rmNames)

I also like think generally having one canonical error message for the same issue is better than being able to return a bunch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree that sorting on rmNames is the best option -- pushed a new commit with that

@carolinaecalderon carolinaecalderon merged commit 54aa739 into main Mar 5, 2024
70 of 82 checks passed
@carolinaecalderon carolinaecalderon deleted the carolinac/fix-multirm-test-flake branch March 5, 2024 16:20
maxrussell pushed a commit that referenced this pull request Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants