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 warning about already initialized constants in rake tests within tests #3210

Merged
merged 3 commits into from
Sep 13, 2023

Conversation

murny
Copy link
Contributor

@murny murny commented Sep 13, 2023

Context

Our test output was polluting the console with the following warnings:

/jupiter/lib/tasks/batch_ingest.rake:1: warning: already initialized constant INGEST_REPORTS_LOCATION
/jupiter/lib/tasks/batch_ingest.rake:1: warning: previous definition of INGEST_REPORTS_LOCATION was here
/jupiter/lib/tasks/batch_ingest.rake:2: warning: already initialized constant INDEX_OFFSET
/jupiter/lib/tasks/batch_ingest.rake:2: warning: previous definition of INDEX_OFFSET was here

Appears we were loading the same rake tasks multiple times, which attempts to redefine the CONSTANTS in batch_ingest.rake file.

We can simply just load our rake tasks in our tests in a smarter fashion. Load them once, and don't load them again if they are already loaded.

…tests. We were loading the same rake tasks multiple times
class AddToPreservationQueueTaskTest < ApplicationSystemTestCase

setup do
Jupiter::Application.load_tasks if Rake::Task.tasks.empty?
Copy link
Contributor Author

@murny murny Sep 13, 2023

Choose a reason for hiding this comment

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

Same code as before, just moved it into the setup block (which will run before each and every test) and only load the tasks if they haven't been loaded before.

This makes the warnings go away as we are not loading the tasks multiple times.

Copy link
Member

@pgwillia pgwillia left a comment

Choose a reason for hiding this comment

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

👍 LGTM! An elegant solution.

As an aside, the branch wasn't working on my machine initially but it had nothing to do with these particular changes. It had a conflict in the Chromedriver versions. I deleted /usr/bin/chromedriver and then reinstalled with sudo snap refresh chromium

@murny murny merged commit 8766fbe into master Sep 13, 2023
2 checks passed
@murny murny deleted the Fix-Already-Initialized-Constant-Warnings branch September 13, 2023 23:59
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