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(common): Remove LinkedChunkBuilderTest #4695

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Feb 19, 2025

This patch adds the new from_all_chunks function in the
linked_chunk::lazy_loader module. It is only used for testing
purposes. It aims at replacing LinkedChunkBuilderTest.
Why? Because from_all_chunks uses from_last_chunk and
insert_new_first_chunk: if from_all_chunks is able to find all
errors that LinkedChunkBuilderTest finds, it's a bingo. Transitively,
it proves that from_last_chunk and insert_new_first_chunk are
correct!

The other patches replaces LinkedChunkBuilderTest and remove it.


@Hywan Hywan requested a review from a team as a code owner February 19, 2025 16:23
@Hywan Hywan requested review from bnjbvr and removed request for a team February 19, 2025 16:23
@Hywan Hywan requested review from poljar and removed request for bnjbvr February 19, 2025 16:32
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 87.09677% with 4 lines in your changes missing coverage. Please review.

Project coverage is 85.90%. Comparing base (5c57631) to head (181bd84).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
.../matrix-sdk-common/src/linked_chunk/lazy_loader.rs 83.33% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4695   +/-   ##
=======================================
  Coverage   85.90%   85.90%           
=======================================
  Files         292      292           
  Lines       33909    33852   -57     
=======================================
- Hits        29129    29082   -47     
+ Misses       4780     4770   -10     

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

Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

Makes sense, I left a couple of nits.

// Chunk with no next chunk comes last.
chunks.sort_by(|a, b| b.next.cmp(&a.next));

let last_chunk = chunks.pop().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that this is meant to be a test function, but it isn't marked as cfg(test) and those unneeded unwraps bother me.

Why not replace the is_empty() check with a:

let Some(last_chunk) = vec.last() else {
     return Ok(None)
};

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not behind a cfg(test) because it's used by other crates :-/.

I can do a pop() else yup.

Copy link
Member Author

@Hywan Hywan Feb 21, 2025

Choose a reason for hiding this comment

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

Actually the pop cannot fail because chunks is guaranteed to not be empty. I am adding a // SAFETY comment, and I am replacing unwrap by expect.

let chunk_identifier_generator =
ChunkIdentifierGenerator::new_from_previous_chunk_identifier(last_chunk_identifier);

let mut linked_chunk = from_last_chunk(Some(last_chunk), chunk_identifier_generator)?.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if you can get rid of this one, but at least put an expect() there instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, let's add an expect. For the record, it's purely used for testing purposes, but I share your concerns.

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've changed for a else { return Ok(None); } here.

This patch adds the new `from_all_chunks` function in the
`linked_chunk::lazy_loader` module. It is only used for testing
purposes. It aims at replacing `LinkedChunkBuilderTest` (see next
patches). Why? Because `from_all_chunks` uses `from_last_chunk` and
`insert_new_first_chunk`: if `from_all_chunks` is able to find all
errors that `LinkedChunkBuilderTest` finds, it's a bingo. Transitively,
it proves that `from_last_chunk` and `insert_new_first_chunk` are
correct!
This patch replaces all usages of `LinkedChunkBuilderTest` by
`from_all_chunks`.
This patch removes `LinkedChunkBuilderTest` and updates tests
accordingly.
@Hywan Hywan force-pushed the chore-common-remove-linked-chunk-builder-test-part-2 branch from 130f5ff to 181bd84 Compare February 21, 2025 09:29
@Hywan Hywan merged commit bdf5fad into matrix-org:main Feb 21, 2025
42 checks passed
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.

2 participants