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 tests for queued jobs in Laravel 9 #501

Merged
merged 2 commits into from
Nov 30, 2022
Merged

Add tests for queued jobs in Laravel 9 #501

merged 2 commits into from
Nov 30, 2022

Conversation

imjoehaines
Copy link
Contributor

Goal

Adds tests for exception handling in queued jobs in the Laravel 9 fixture

I've used docker's init feature to allow running multiple processes in the same docker container. This simplifies the fixture setup as otherwise we'd need 2 more containers — a database and queue worker

When using the init flag docker will spawn an init process as PID 1, which can then spawn more processes. This lets us run the HTTP server and queue worker in the same database. I've configured the fixture to use an sqlite database as well, to avoid having to run a separate database server

The queue worker is started by a new "I start the laravel queue worker" step, which uses docker compose exec to run the actual command in the same container that's running the HTTP server. I've monkey patched this into the Maze::Docker class, but am intending on contributing it back at some point — the change is done but needs some tests in MR itself

The same test will be implemented in other fixtures in separate PRs to avoid this being unreviewable

In order to run the queue worker and HTTP server in the same docker
container, I've enabled the 'init' option. This runs an init process as
PID 1, which then spawns the queue worker & HTTP server

See https://docs.docker.com/config/containers/multi-service_container/
and https://docs.docker.com/compose/compose-file/compose-file-v3/#init

We _could_ do this with multiple containers, but that adds a lot more
complexity for no real gain since we'd need 2 additional containers to
accomplish the same thing (a database and a queue worker)

This reduces the number of moving parts, making less likely to flake
This shows the 'job.attempts' gets incremented for each attempt
@imjoehaines imjoehaines requested a review from a team November 29, 2022 15:51
Base automatically changed from update-maze-runner to master November 29, 2022 21:05
@imjoehaines imjoehaines merged commit 76eb595 into master Nov 30, 2022
@imjoehaines imjoehaines deleted the queue-tests branch November 30, 2022 08:03
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