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 search test NPE #11749

Merged
merged 6 commits into from
Sep 13, 2024
Merged

Fix search test NPE #11749

merged 6 commits into from
Sep 13, 2024

Conversation

LoayGhreeb
Copy link
Member

@LoayGhreeb LoayGhreeb commented Sep 10, 2024

Search tests sometimes throw NullPointerException (example: https://github.com/JabRef/jabref/actions/runs/10759644260/job/29836573460).

This issue occurs because multiple tests for the same library share the same index path. The index is closed in a background thread, which may lead to subsequent tests accessing the same index before the previous test closing index finishes.

Although the org.jabref.gui.util.CurrentThreadTaskExecutor is used to run background tasks sequentially for tests, a different task executor (org.jabref.logic.util.HeadlessExecutorService#INSTANCE) is used for closing the index (due to LoayGhreeb#6).

  • Attempt to resolve the issue by using @TempDir for the index path.
  • Added closeAndWait to wait until the task is finished. Using @TempDir only didn't resolve the issue because the next test could start, and @TempDir would be removed before the closing task finished.

Follow-up to #11542.
Closes https://github.com/JabRef/jabref-issue-melting-pot/issues/527.

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@LoayGhreeb LoayGhreeb added the dev: testing Related to tests label Sep 10, 2024
@@ -315,6 +315,11 @@ public void close() {
HeadlessExecutorService.INSTANCE.execute(this::closeIndex);
}

@Override
public void closeAndWait() {
HeadlessExecutorService.INSTANCE.executeAndWait(this::closeIndex);
Copy link
Member

Choose a reason for hiding this comment

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

Can we pass this dependency in the constructor as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you check this commit 81a30ff (#11749)? added a boolean parameter to the constructor.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, sorry, I did not clarfiy. I meant the Executor Service, that would partially also improve the test siutation

Copy link
Member

Choose a reason for hiding this comment

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

TL;DR: Refactor DefaultLinkedFilesIndexer NOT to depend on HeadlessExecutorService.INSTANCE, but to have an ExecutorService passed using the constructor.

--> follow-up PR

github-actions[bot]

This comment was marked as resolved.

Copy link
Contributor

github-actions bot commented Sep 13, 2024

The build for this PR is no longer available. Please visit https://builds.jabref.org/main/ for the latest build.

@@ -315,6 +315,11 @@ public void close() {
HeadlessExecutorService.INSTANCE.execute(this::closeIndex);
}

@Override
public void closeAndWait() {
HeadlessExecutorService.INSTANCE.executeAndWait(this::closeIndex);
Copy link
Member

Choose a reason for hiding this comment

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

TL;DR: Refactor DefaultLinkedFilesIndexer NOT to depend on HeadlessExecutorService.INSTANCE, but to have an ExecutorService passed using the constructor.

--> follow-up PR

@koppor koppor added this pull request to the merge queue Sep 13, 2024
Merged via the queue into main with commit ba9de82 Sep 13, 2024
26 checks passed
@koppor koppor deleted the fix-search-test branch September 13, 2024 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev: testing Related to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants