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

Library::removeBookById() updates the reader list and the search DB #485

Merged
merged 5 commits into from
Apr 12, 2021

Conversation

veloman-yunkan
Copy link
Collaborator

Fixes #478

I added a new test-suite XmlLibraryTest so that I could make use of the Library::getReaderById() method (a library constructed from an OPDS stream doesn't contain local books).

The `XmlLibraryTest.removeBookByIdDropsTheReader` unit-test fails,
demonstrating a bug in `kiwix::Library::removeBookById()`.
This fix makes the `XmlLibraryTest.removeBookByIdDropsTheReader`
unit-test pass.
The new unit-test fails with a reason not expected before it was
written. The `Library::filter()` operation returns a correct result
after the call to `removeBookById()` (this was a surprise!) but it has
a side-effect of re-adding an empty book with the id still surviving
in the search DB (the emptiness of this re-created book doesn't allow
it to pass the other filtering criteria, which explains why the result
of `Library::filter()` is correct). Had to add a special check
to the new unit-test against that hidden side-effect of
`Library::removeBookById()` + `Library::filter()` combination.
This changes how the `XmlLibraryTest.removeBookByIdUpdatesTheSearchDB`
unit-test fails.
This fix makes the `XmlLibraryTest.removeBookByIdUpdatesTheSearchDB`
unit-test pass.
@codecov
Copy link

codecov bot commented Apr 9, 2021

Codecov Report

Merging #485 (ec9186b) into master (ba44033) will increase coverage by 0.07%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #485      +/-   ##
==========================================
+ Coverage   63.07%   63.14%   +0.07%     
==========================================
  Files          50       50              
  Lines        3504     3506       +2     
  Branches     1770     1771       +1     
==========================================
+ Hits         2210     2214       +4     
+ Misses       1292     1290       -2     
  Partials        2        2              
Impacted Files Coverage Δ
src/library.cpp 68.08% <100.00%> (+0.80%) ⬆️

Continue to review full report at Codecov.

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

@@ -331,7 +331,7 @@ Library::BookIdCollection Library::filter(const Filter& filter)
{
BookIdCollection result;
for(auto id : getBooksByTitleOrDescription(filter)) {
if(filter.acceptByNonQueryCriteria(m_books[id])) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This bug was introduced in #460 because Library::filter() is not declared const.

@mgautierfr mgautierfr merged commit 5c289ab into master Apr 12, 2021
@mgautierfr mgautierfr deleted the fix_for_issue478 branch April 12, 2021 13:05
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.

kiwix::Library::removeBookById() doesn't update m_readers and m_bookDB
2 participants