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 solr query in MultipleMembershipChecker and refactor to improve readability #5055

Merged
merged 2 commits into from
Jul 28, 2021

Conversation

elrayle
Copy link
Contributor

@elrayle elrayle commented Jul 27, 2021

The solr query being generated was causing the multiple membership #check to fail if there were two collections of the same single membership type even if the item was not in both collections. The tests failed to catch this very common scenario.

This led to a refactor of the code which was complex and difficult to follow. Now each method has one and only one task and is clearly named for that task.

Also the reason the tests failed to catch the common scenario is that the access to solr was heavily mocked and returned what was expected to be returned from solr and not what was actually being returned from solr. This was hiding errors in the generated solr query for multiple tests. The tests are rewritten to organize them into clear scenarios based on the options for passed in parameters and the state of membership for the item using real solr access.

@samvera/hyrax-code-reviewers

# @param collection_ids [Array<String>] a list of collection identifiers
# @param include_current_members [Boolean] a flag to also scan an object's
# current collection memberships
# @param include_current_members [Boolean] if true, include item's existing collections in check; else if false, check passed in collections only
Copy link
Contributor

Choose a reason for hiding this comment

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

can we shorten the line lengths here? i try to set a soft cap at 80 chars especially in consideration of samvera/bixby#48.

since these lines can be wrapped without syntax considerations, it seems best to do so.

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 shortened all long lines.

@@ -108,6 +108,7 @@ def clean_active_fedora_repository
# The JS is executed in a different thread, so that other thread
# may think the root path has already been created:
ActiveFedora.fedora.connection.send(:init_base_path)
Hyrax.persister.wipe! if Hyrax.config.query_index_from_valkyrie
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm not following this. the Hyrax.persister is independent of the index, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You would think that. And perhaps this should be somewhere else, but I'm just using the existing wipe! method defined in wings persister.

# Deletes all resources from Fedora and Solr
def wipe!
Hyrax::SolrService.delete_by_query("*:*")
Hyrax::SolrService.commit
ActiveFedora::Cleaner.clean!
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative...

# define in Hyrax::SolrService
def wipe!
   Hyrax::SolrService.delete_by_query("*:*") 
   Hyrax::SolrService.commit 
end
# update in Wings::Valkyrie::Persister
def wipe!
  Hyrax::SolrService.wipe!
  ActiveFedora::Cleaner.clean!
end

Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think it's safe to assume that Hyrax.persister is a the wings persister (it's not for many tests).

i think i'm not understanding the use case in general, either. this method is named #clean_active_fedora_repository; when/why does that need to clear the custom, non-AF solr index?

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 added a wipe! method to Hyrax::SolrService and moved that call to the :clean_repo section of spec_helper.rb since that is what triggers the call from the spec. I think the assumption here is that the writer of the test does want all repos (e.g. Fedora, Redis, Solr) cleared to start the tests with a clean slate, including Valkyrie solr if it is in use.

Long term, this should perhaps call Hyrax.persister.wipe! with the theory that if :clean_repo is being called by a spec, then that persister was used. Or we may want to make this more granular (e.g. :wipe_hyrax_persister, :wipe_solr, etc.).

@elrayle elrayle force-pushed the refactor/multi_mem_checker branch from 1f9619e to 50c2e66 Compare July 27, 2021 20:09
…eadability

The code was complex and difficult to follow.  I refactored so that each method has one and only one task and is clearly named for that task.

Also, tests were heavily mocked and were hiding errors in the generated solr query.  The tests are rewritten to organize them into clear test scenarios with real solr access.
@elrayle elrayle force-pushed the refactor/multi_mem_checker branch from 50c2e66 to 9780d95 Compare July 27, 2021 21:31
@elrayle
Copy link
Contributor Author

elrayle commented Jul 27, 2021

FYI... I kicked off the failing tests again. The two that failed on the last round fail locally whether on my branch or main. And they passed for some ruby versions. It looks like they may be random failures.

@no-reply
Copy link
Contributor

yeah. the two failing specs are new in the last week or so, and appear to be a test order issue. i'll try to clear it later today.

elrayle added a commit that referenced this pull request Jul 28, 2021
DO NOT MERGE - pending merge of PR #5055

----
* deprecates `Hyrax::CollectionBehavior#add_member_objects`
* updates all places that call it to `Hyrax::Collections::CollectionMemberService.add_members`
elrayle added a commit that referenced this pull request Jul 28, 2021
DO NOT MERGE - pending merge of PR #5055

----
* deprecates `Hyrax::CollectionBehavior#add_member_objects`
* updates all places that call it to `Hyrax::Collections::CollectionMemberService.add_members`
elrayle added a commit that referenced this pull request Jul 28, 2021
DO NOT MERGE - pending merge of PR #5055

----
* deprecates `Hyrax::CollectionBehavior#add_member_objects`
* updates all places that call it to `Hyrax::Collections::CollectionMemberService.add_members`
@no-reply no-reply merged commit 495180d into main Jul 28, 2021
@no-reply no-reply deleted the refactor/multi_mem_checker branch July 28, 2021 22:25
elrayle added a commit that referenced this pull request Jul 28, 2021
DO NOT MERGE - pending merge of PR #5055

----
* deprecates `Hyrax::CollectionBehavior#add_member_objects`
* updates all places that call it to `Hyrax::Collections::CollectionMemberService.add_members`
elrayle added a commit that referenced this pull request Jul 29, 2021
DO NOT MERGE - pending merge of PR #5055

----
* deprecates `Hyrax::CollectionBehavior#add_member_objects`
* updates all places that call it to `Hyrax::Collections::CollectionMemberService.add_members`
no-reply pushed a commit that referenced this pull request Aug 10, 2021
DO NOT MERGE - pending merge of PR #5055

----
* deprecates `Hyrax::CollectionBehavior#add_member_objects`
* updates all places that call it to `Hyrax::Collections::CollectionMemberService.add_members`
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