Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This project supports the Gunicorn web server. Gunicorn's server design includes a primary "arbiter" process that spawns "worker" processes. Workers are child processes, each with their own running server. Workers are implemented as Python classes. Custom workers can be supplied.
This project also supports the Uvicorn web server. In the past, Uvicorn supplied workers for use with Gunicorn. The Uvicorn workers were not tested. The
uvicorn.workers
module was completely omitted from coverage measurement due to use of the coverage.pyinclude
setting to specify source files.Efforts were made to test the Uvicorn workers (encode/uvicorn#1834, encode/uvicorn#1995), but the workers were arbitrarily deprecated and moved to someone's personal project (encode/uvicorn#2302), instead of an Encode-managed project as would have been expected (encode/uvicorn#517 (comment)).
Rather than introducing a production dependency on a separate Uvicorn workers package that is not managed by Encode, this PR will add the Gunicorn workers directly to this project.
Changes
Workers
This PR will add the code from
uvicorn.workers
to a new moduleinboard/gunicorn_workers.py
. The code will be preserved as it was prior to deprecation, with a copy of the Uvicorn license and necessary updates for compliance with the code quality settings in this project:[attr-defined]
- Module "uvicorn.main" does not explicitly export attribute "Server"[import-untyped]
-gunicorn.arbiter
[import-untyped]
-gunicorn.workers.base
[misc]
- Class cannot subclass "Worker" (has type "Any")[type-arg]
- Missing type parameters for generic type "dict" (onconfig_kwargs
)Tests
This PR will add tests of 100% of the Gunicorn worker code to a new module
tests/test_gunicorn_workers.py
.A test fixture starts a subprocess running Gunicorn with a Uvicorn worker and an ASGI app. The subprocess includes an instance of
httpx.Client
for HTTP requests to the Uvicorn worker's ASGI app, and saves its output to a temporary file for assertions onstdout
/stderr
. Tests can send operating system signals to the process.The coverage.py configuration will be updated for subprocess test coverage measurement. Changes to coverage measurement include:
.gitignore
ignores files named.coverage.*
because many coverage files are generated when subprocesses are measured in parallel mode)COVERAGE_PROCESS_START
environment variablecoverage_enable_subprocess
package to invokecoverage.process_startup
contributing.md
about how to omit subprocess testsRelated
uvicorn.workers
module encode/uvicorn#2302