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

[8.x] Add scheduler integration tests #39862

Merged
merged 10 commits into from
Dec 2, 2021

Conversation

inxilpro
Copy link
Contributor

@inxilpro inxilpro commented Dec 1, 2021

This adds two tests for the scheduler. The first tests scheduled callbacks, and the second tests scheduled commands.

Scheduled callbacks are relatively easy to test because they always run in the same process as the scheduler. These tests verify execution order, exception handling, and mutex processing (for onOneServer).

Scheduled commands are trickier to test because they rely on spawning an external php artisan ... process, which is currently not supported in Orchestra Testbench. To work around this issue, we write a custom artisan script that is used for our test. It includes:

  1. A custom console command (which must exist outside of the scope of the test so that it's available to execute in a secondary process)
  2. Command and scheduler registration (again, necessary because half the test does not execute inside the context of PHPUnit)
  3. A custom version of the typical artisan script that is modified to account for the location of the testbench-core/laravel directory

(This file is removed during the tear down phase.)

The command tests work by writing to a log file and then checking that the expected output exists in that file. This means that we can use the full Laravel scheduler (including the call to php artisan schedule:finish when running in background) without having to mock or fake anything.

@inxilpro inxilpro changed the title [8.x] Add scheduler tests for callback events [8.x] Add scheduler integration tests Dec 2, 2021
@taylorotwell taylorotwell merged commit f4f8e32 into laravel:8.x Dec 2, 2021
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