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

Add unit test for each queue jobs class #9899

Open
29 of 46 tasks
touhidurabir opened this issue Apr 19, 2024 · 7 comments
Open
29 of 46 tasks

Add unit test for each queue jobs class #9899

touhidurabir opened this issue Apr 19, 2024 · 7 comments
Assignees
Labels
Housekeeping:2:Urgent Any dependency management or refactor that must be done soon to fix or avoid a significant problem.
Milestone

Comments

@touhidurabir
Copy link
Member

touhidurabir commented Apr 19, 2024

Describe the problem
Starting from 3.4.0 we have queue jobs to handle long running tasks or for tasks that need to done later . Our queue jobs implementation is an extended implementation of Laravel queue jobs.

The problem arise or will arise when any of the jobs structure will update but there is one or more pending jobs with older structure already dispatched in queue waiting to get executed . This problem get more complex with the upgrade of newer version when older structure based job still in queue as they may continue to fail and no way to resolve it after upgrade which may lead to undesirable outcome.

Describe the proposal
The initial plan was to force to run all pending queue jobs before upgrade which proposed at Add pre-flight check for pending jobs before running upgrade . This was a very simple and easy approach but may not suited for all possible cases . Also a job class structure or handle implementation may need to update based on requirement.

After some detailed discussion, we decided to add unit tests for each job class to make sure the consistence update the job class structure and handle method implementation . The idea is to try to mock each of jobs class to make sure it's on even after any update to it.

Impacted version
OJS, OMP or OPS version 3.4.0 and main

Additional information
Details discussion at Right approach to handle pending queue jobs at upgrade

Job classes to have unit tests

Stable-3.4.0

OJS
  • APP\jobs\doi\DepositIssue
  • APP\jobs\notifications\IssuePublishedNotifyUsers
  • APP\jobs\notifications\OpenAccessMailUsers
  • APP\jobs\statistics\CompileCounterSubmissionDailyMetrics
  • APP\jobs\statistics\CompileCounterSubmissionInstitutionDailyMetrics
  • APP\jobs\statistics\CompileIssueMetrics
  • APP\jobs\statistics\CompileSubmissionGeoDailyMetrics
  • APP\jobs\statistics\CompileUniqueInvestigations
  • APP\jobs\statistics\CompileUniqueRequests
  • APP\jobs\statistics\CompileUsageStatsFromTemporaryRecords
  • APP\jobs\statistics\DeleteUsageStatsTemporaryRecords
  • APP\jobs\statistics\ProcessUsageStatsLogFile
OMP
  • APP\jobs\statistics\CompileCounterSubmissionDailyMetrics
  • APP\jobs\statistics\CompileCounterSubmissionInstitutionDailyMetrics
  • APP\jobs\statistics\CompileSeriesMetrics
  • APP\jobs\statistics\CompileSubmissionGeoDailyMetrics
  • APP\jobs\statistics\CompileUniqueInvestigations
  • APP\jobs\statistics\CompileUniqueRequests
  • APP\jobs\statistics\CompileUsageStatsFromTemporaryRecords
  • APP\jobs\statistics\DeleteUsageStatsTemporaryRecords
  • APP\jobs\statistics\ProcessUsageStatsLogFile
OPS
  • APP\jobs\statistics\CompileCounterSubmissionDailyMetrics
  • APP\jobs\statistics\CompileCounterSubmissionInstitutionDailyMetrics
  • APP\jobs\statistics\CompileSubmissionGeoDailyMetrics
  • APP\jobs\statistics\CompileUniqueInvestigations
  • APP\jobs\statistics\CompileUniqueRequests
  • APP\jobs\statistics\CompileUsageStatsFromTemporaryRecords
  • APP\jobs\statistics\DeleteUsageStatsTemporaryRecords
  • APP\jobs\statistics\ProcessUsageStatsLogFile
PKP-LIB
  • PKP\jobs\bulk\BulkEmailSender
  • PKP\jobs\doi\DepositContext
  • PKP\jobs\doi\DepositSubmission
  • PKP\jobs\email\EditorialReminder
  • PKP\jobs\metadata\BatchMetadataChangedJob
  • PKP\jobs\metadata\MetadataChangedJob
  • PKP\jobs\notifications\NewAnnouncementNotifyUsers
  • PKP\jobs\notifications\StatisticsReportMail
  • PKP\jobs\notifications\StatisticsReportNotify
  • PKP\jobs\statistics\ArchiveUsageStatsLogFile
  • PKP\jobs\statistics\CompileContextMetrics
  • PKP\jobs\statistics\CompileMonthlyMetrics
  • PKP\jobs\statistics\CompileSubmissionMetrics
  • PKP\jobs\statistics\RemoveDoubleClicks
  • PKP\jobs\submissions\RemoveSubmissionFileFromSearchIndexJob
  • PKP\jobs\submissions\RemoveSubmissionFromSearchIndexJob
  • PKP\jobs\submissions\UpdateSubmissionSearchJob

PRs
pkp-lib --> #9981
ojs --> pkp/ojs#4285

@touhidurabir touhidurabir added the Housekeeping:2:Urgent Any dependency management or refactor that must be done soon to fix or avoid a significant problem. label Apr 19, 2024
@touhidurabir touhidurabir added this to the 3.4.0-6 milestone Apr 19, 2024
@touhidurabir touhidurabir modified the milestones: 3.4.0-6, 3.4.0-x Apr 19, 2024
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue May 23, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue May 23, 2024
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue May 23, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue May 23, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue May 23, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue May 23, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue May 23, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue May 23, 2024
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue May 23, 2024
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue May 30, 2024
…d PKP\jobs\bulk\BulkEmailSender along with mockery package version update
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue May 30, 2024
…omSearchIndexJob and PKP\jobs\submissions\RemoveSubmissionFileFromSearchIndexJob
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jun 6, 2024
@touhidurabir touhidurabir self-assigned this Jun 9, 2024
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jun 9, 2024
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jun 13, 2024
…d PKP\jobs\bulk\BulkEmailSender along with mockery package version update
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jun 13, 2024
…omSearchIndexJob and PKP\jobs\submissions\RemoveSubmissionFileFromSearchIndexJob
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jun 13, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jun 13, 2024
@touhidurabir
Copy link
Member Author

@asmecher can you take a look the PR at #9899 (comment) for the OJS only ?

@touhidurabir
Copy link
Member Author

touhidurabir commented Jun 13, 2024

@withanage can you please take a look at this particular implementation to mock the Guzzle Http Client for unit tests .

implementation of mock at PKPTestCase and to facilitate it , I had to add few logic within the core app at PKPApplication and PKPContainer.

Long story short, we like to mock the guzzle requests without making any actual request but our very static like Application::get()->getHttpClient() implementation kind of make it very hard to mock it . Me and @asmecher was discussing about it and we would like to get your suggestion and advice on this as I am not very happy with this implementation but at the same time could not figure out any better approach .

We can also decide not to mock it for 3.4.0 and have something better like Laravel Http in 3.5. But that means either we have to ditch those specific queue job classes unit test or have unit test and allow hitting real url, both option does not seems very best.

Also any suggestion or advise on approach on the job test implementation are welcomed .

@withanage
Copy link
Member

withanage commented Jun 13, 2024

Hi @touhidurabir

PKPTestCase

I have looked at your test. I also think that the way you have implmented, it is the best possible way to mock the Guzzle HTTP client and I can't offer a better approach either.

General support

  • I would generally not use real-urls for php-unit-tests.
  • Although we can consider changing the Laravel Http to 3.5, my opinion would be to support the unit tests for 3.4. Especially, as the job queues are a very difficult and complex use-case, I think only automated and isolated unit tests would be long-term best approach.

@asmecher
Copy link
Member

@touhidurabir, for some reason your .php additions in https://github.com/pkp/ojs/pull/4285/files are being flagged as binary by Github; is there some unusual encoding or something causing this?

@asmecher
Copy link
Member

@touhidurabir, for some reason your .php additions in https://github.com/pkp/ojs/pull/4285/files are being flagged as binary by Github; is there some unusual encoding or something causing this?

^ I suspect it's the ^@*^@ part of the serialized object. I suppose we could prevent that from happening using base64 or chr or something, but I don't know if it's a problem worth solving; I'm OK to ignore it.

@touhidurabir
Copy link
Member Author

@asmecher I just noticed the issue in github as it is not causing any issue for me in my editor(VS code or sublime) . I think we can easily solve it using the base64 encode/decode. At least anyone one can see the test file but wont be able to understand the what props are defined there with a single look as base64 encoded string .

I think it's worth solving and will only take about an hour or two to update all the tests . for me it's not causing any issue in my editor but may cause issue with different editor for other .

touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jun 15, 2024
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jun 15, 2024
@touhidurabir
Copy link
Member Author

@asmecher I have updated the tests to resolve the binary file issue . Good to take a look now .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Housekeeping:2:Urgent Any dependency management or refactor that must be done soon to fix or avoid a significant problem.
Projects
None yet
Development

No branches or pull requests

4 participants