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

fix(i): Tests with primary doc patch update events #2850

Merged
merged 7 commits into from
Jul 23, 2024

Conversation

nasdf
Copy link
Member

@nasdf nasdf commented Jul 19, 2024

Relevant issue(s)

Resolves #2849

Description

This PR fixes an issue with primary document patch updates. We also now assert that the document updates match the expected updates. We can most likely remove the events test package now that every test asserts the expected events.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

make test

Specify the platform(s) on which this was tested:

  • MacOS

@nasdf nasdf self-assigned this Jul 19, 2024
@nasdf nasdf added bug Something isn't working area/testing Related to any test or testing suite labels Jul 19, 2024
@nasdf nasdf added this to the DefraDB v0.13 milestone Jul 19, 2024
Copy link

codecov bot commented Jul 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.39%. Comparing base (dc76eba) to head (d6c0db8).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2850      +/-   ##
===========================================
- Coverage    79.43%   79.39%   -0.04%     
===========================================
  Files          323      323              
  Lines        24683    24681       -2     
===========================================
- Hits         19606    19594      -12     
- Misses        3678     3684       +6     
- Partials      1399     1403       +4     
Flag Coverage Δ
all-tests 79.39% <100.00%> (-0.04%) ⬇️

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

Files Coverage Δ
client/definitions.go 100.00% <100.00%> (ø)
internal/db/collection.go 73.65% <100.00%> (-0.40%) ⬇️
internal/db/collection_update.go 76.92% <ø> (-0.99%) ⬇️

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc76eba...d6c0db8. Read the comment docs.

@nasdf nasdf requested a review from a team July 23, 2024 03:07
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Thank you very much for removing that test package Keenan, just a couple of small todo's for you before merge :)

func waitForUpdateEvents(
s *state,
nodeID immutable.Option[int],
updates map[string]struct{},
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: Please make it a little clearer as to what updates is, either by renaming (preferred, perhaps to docIDs) or documentation.

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed to docIDs

s.nodeP2P[id].expectedDocHeads[evt.DocID] = evt.Cid
}
if i >= len(s.nodeConfigs) {
continue // not testing network state
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: This comment caused me a fair bit of confusion, and I initially thought it was skipping P2P tests (via some strange mechanic that I didn't yet understand). Can you please rework the comment a bit?

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the docs and broke out the rest into a more dedicated function. Hopefully its more clear now.


case <-time.After(eventTimeout):
require.Fail(s.t, "timeout waiting for update event")
expect := make(map[string]struct{})
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: Please set the length in the make call instead of resizing the map for each item.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I didn't know you could pre allocate maps.

// getEventsForDelete returns a map of expected update events for a document delete action.
func getEventsForDelete(docID client.DocID) map[string]struct{} {
expect := make(map[string]struct{})
expect[docID.String()] = struct{}{}
Copy link
Contributor

@AndrewSisley AndrewSisley Jul 23, 2024

Choose a reason for hiding this comment

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

todo: Please dont grow the map like this, please either set the length on make, or (IMO) better replace this with:

return map[string]struct{}{
   docID.String(): {},
}

I would probably delete the getEventsForDelete entirely and just do this inline where getEventsForDelete is called, it saves readers from having to bounce around the file when reading (I won't push for that as a todo though :)).

Copy link
Member Author

Choose a reason for hiding this comment

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

I dropped the function and created the map like you suggested.

@nasdf nasdf merged commit 8e4690f into sourcenetwork:develop Jul 23, 2024
40 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing Related to any test or testing suite bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration tests don't account for primary document patches
2 participants