Skip to content

Don't override Equals, GetHashCode#3660

Merged
imnasnainaec merged 7 commits intomasterfrom
equals-gethashcode
Mar 11, 2025
Merged

Don't override Equals, GetHashCode#3660
imnasnainaec merged 7 commits intomasterfrom
equals-gethashcode

Conversation

@imnasnainaec
Copy link
Collaborator

@imnasnainaec imnasnainaec commented Mar 5, 2025

We thought they were only used in testing, but they snuck into production via 4 uses of .Remove as well as uses of .Contains in other model methods.


This change is Reviewable

@imnasnainaec imnasnainaec added backend test maintenance Issue that makes it difficult to maintain the software or to upgrade installations post-release. labels Mar 5, 2025
@imnasnainaec imnasnainaec self-assigned this Mar 5, 2025
@github-actions

This comment has been minimized.

@codecov
Copy link

codecov bot commented Mar 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.26%. Comparing base (7d92ffb) to head (e888c9f).
Report is 28 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3660      +/-   ##
==========================================
- Coverage   74.24%   73.26%   -0.99%     
==========================================
  Files         285      285              
  Lines       11143    10629     -514     
  Branches     1373     1322      -51     
==========================================
- Hits         8273     7787     -486     
+ Misses       2476     2452      -24     
+ Partials      394      390       -4     
Flag Coverage Δ
backend 82.81% <100.00%> (-1.17%) ⬇️
frontend 65.78% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@jasonleenaylor jasonleenaylor left a comment

Choose a reason for hiding this comment

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

I had two comments worth considering, but overall :lgtm:

Reviewed 33 of 47 files at r1, 14 of 14 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @imnasnainaec)


Backend/Services/WordService.cs line 109 at r2 (raw file):

            var rmCount = wordWithAudioToDelete.Audio.RemoveAll(a => a.FileName == fileName);
            if (rmCount == 0)

There is nothing at all wrong with this change, but I found it less clear than the original. So unless we expect Audio to have duplicate entries with the same filename I would slightly prefer the original. Should be bring @andracc in as a tie breaker? 😄

Code quote:

            var rmCount = wordWithAudioToDelete.Audio.RemoveAll(a => a.FileName == fileName);
            if (rmCount == 0)

Backend.Tests/Controllers/UserRoleControllerTests.cs line 241 at r2 (raw file):

        [Test]
        public async Task TestUpdateUserRoleNoChange()

So this test no longer had any value?

new MergeUndoIds { ParentIds = _parentIds1, ChildIds = _childIds1 }.GetHashCode(),
Is.EqualTo(new MergeUndoIds { ParentIds = _parentIds1, ChildIds = _childIds1 }.GetHashCode()));
var merge = new MergeUndoIds { ParentIds = ["parent1", "parent2"], ChildIds = ["child1", "child2"] };
Assert.That(merge.Clone(), Is.EqualTo(merge).UsingPropertiesComparer());
Copy link
Contributor

Choose a reason for hiding this comment

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

this test will pass even if the clone is not a deep clone. So you might want to check that Parent and Child Ids don't refer to the same lists. Just a thought though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, yes. This is why you use

            assertionChain
                .ForCondition(!ReferenceEquals(comparands.Subject, comparands.Expectation))
                .BecauseOf(context.Reason)
                .FailWith("Subject and Expectation for {0} should not reference the same instance in memory.", context.CurrentNode.Description);

I think for now I'll leave it and make an issue for considering that with all our Clone tests. The main purpose of the tests is to make sure no property was left out, but it would be valuable to make sure they've all been truly cloned.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@hahn-kev hahn-kev left a comment

Choose a reason for hiding this comment

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

I'll bet that felt good to delete all that code

Copy link
Collaborator Author

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

Reviewable status: 44 of 47 files reviewed, 1 unresolved discussion (waiting on @hahn-kev and @jasonleenaylor)


Backend.Tests/Controllers/UserRoleControllerTests.cs line 241 at r2 (raw file):

Previously, jasonleenaylor (Jason Naylor) wrote…

So this test no longer had any value?

Very little. Most of our Repository Mocks don't have a "NotModified" case, and this test depends on the

            if (foundUserRole.ContentEquals(userRole))
            {
                return Task.FromResult(ResultOfUpdate.NoChange);
            }

case of the Update method in UserRoleRepositoryMock, which was the only reason we had UserRole.ContentEquals defined. So I thought I'd remove it to have UserRoleRepositoryMock more consistent with the other Mocks.


Backend/Services/WordService.cs line 109 at r2 (raw file):

Previously, jasonleenaylor (Jason Naylor) wrote…

There is nothing at all wrong with this change, but I found it less clear than the original. So unless we expect Audio to have duplicate entries with the same filename I would slightly prefer the original. Should be bring @andracc in as a tie breaker? 😄

Reverted.

new MergeUndoIds { ParentIds = _parentIds1, ChildIds = _childIds1 }.GetHashCode(),
Is.EqualTo(new MergeUndoIds { ParentIds = _parentIds1, ChildIds = _childIds1 }.GetHashCode()));
var merge = new MergeUndoIds { ParentIds = ["parent1", "parent2"], ChildIds = ["child1", "child2"] };
Assert.That(merge.Clone(), Is.EqualTo(merge).UsingPropertiesComparer());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, yes. This is why you use

            assertionChain
                .ForCondition(!ReferenceEquals(comparands.Subject, comparands.Expectation))
                .BecauseOf(context.Reason)
                .FailWith("Subject and Expectation for {0} should not reference the same instance in memory.", context.CurrentNode.Description);

I think for now I'll leave it and make an issue for considering that with all our Clone tests. The main purpose of the tests is to make sure no property was left out, but it would be valuable to make sure they've all been truly cloned.

Copy link
Contributor

@jasonleenaylor jasonleenaylor left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @hahn-kev)

Copy link
Collaborator Author

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

Dismissed @hahn-kev from a discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @imnasnainaec)

@imnasnainaec imnasnainaec merged commit 307b949 into master Mar 11, 2025
18 checks passed
@imnasnainaec imnasnainaec deleted the equals-gethashcode branch March 11, 2025 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend maintenance Issue that makes it difficult to maintain the software or to upgrade installations post-release. test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants