Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid Gunicorn worker test subprocess re-spawning
Running subprocesses in tests helps match real-world code usage but also adds complexity. One of the limitations is that the subprocesses must exit properly. If they do not, tests may "flake" (fail intermittently) or there may be more complex problems. One of the problems with the Gunicorn worker tests is that subprocesses seem to be re-spawning. After the `coverage run` command completes with a successful exit code and the test run is concluded, coverage.py keeps generating `.coverage` files. It's possible these files are coming from unterminated subprocesses, but this is unlikely because the tests check that the processes have terminated. Coverage.py offers a configuration setting for handling `SIGTERM` signals (`sigterm = true` on `coverage.run`), and the tests were previously exiting with `SIGTERM` (via `process.terminate()`), but enabling the `sigterm = true` setting has no effect. To check for these unexpected `.coverage` files, a test will be added to the GitHub Actions job that runs the tests. The test is simple - count coverage files in the directory (`find . -name '.coverage*' | wc -l`), wait for ten seconds (`sleep 10`), then count again. If files continue to be generated, the GitHub Actions job will error and exit. To avoid re-spawning subprocesses, this commit will update the Gunicorn process fixture to exit with `SIGQUIT` instead of `SIGTERM`. While this seems to avoid the re-spawning subprocesses, it also leads coverage.py to report incorrect coverage. Coverage.py reports that the ASGI app in the Gunicorn worker test module `test_gunicorn_workers.py` is uncovered, when it obviously is covered (otherwise the tests couldn't pass). To maintain test coverage, this commit will add a pytest fixture with a simplified worker configuration that exits with `SIGTERM` instead of `SIGQUIT`. The new fixture will be used in a test that makes a `GET` request to the worker. This sounds redundant with what was already in the tests, but adding a redundant fixture and test seems to help coverage.py report the correct test coverage. https://coverage.readthedocs.io/en/latest/subprocess.html
- Loading branch information