-
Notifications
You must be signed in to change notification settings - Fork 0
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
Prevent autover from failing when used alongside async frameworks #59
Changes from all commits
e1086e6
d0a6733
fae9e7d
1176fdf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import autover | ||
from starlette.applications import Starlette | ||
|
||
# A simple ASGI server application | ||
# that tries to make use of autover. | ||
# | ||
# Given that autover makes use of | ||
# subprocess.Popen and the program | ||
# workflow depends on that, there | ||
# were some corner cases where | ||
# autover would just crash if we | ||
# tried to get its __version__, | ||
# therefore crashing the whole | ||
# ASGI application. | ||
# | ||
# This test application is used | ||
# with Gunicorn in the unit tests | ||
# (testversion.py), just to check | ||
# if the ASGI application crashes | ||
# or not. | ||
|
||
_ = autover.__version__ | ||
|
||
app = Starlette() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this file a "test support file" rather than an actual test? If so, maybe rename it so it's clearly not a file containing tests, and then no need to exclude specially from nose? (Unless there's some reason that's not possible?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did it that way just to make sure that the file got bundled when creating the package (as everything that is named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do you happen to know if that is a limitation we have put in somewhere here in autover? I wasn't aware of this as a general thing (in setup tools, tox, etc), and I'm only on my phone just now... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
""" | ||
Unit test for autover.Version | ||
""" | ||
import os | ||
import unittest | ||
import subprocess | ||
import sys | ||
import time | ||
import pkg_resources._vendor.packaging.version as packaging_version | ||
from autover import Version | ||
|
||
|
@@ -75,6 +79,7 @@ def pep440(version): | |
|
||
|
||
class TestVersion(unittest.TestCase): | ||
maxDiff=None | ||
|
||
|
||
def git_describe_check(self, describe_tests, index): | ||
|
@@ -160,6 +165,32 @@ def test_git_describe_4(self): | |
def test_git_describe_5(self): | ||
self.git_describe_check(describe_tests, 5) | ||
|
||
#=======================================# | ||
# Compatibility with ASGI applications # | ||
#=======================================# | ||
|
||
def test_run_asgi_server(self): | ||
"""test_run_asgi_server (An ASGI app that uses autover and is launched with Gunicorn should not crash)""" | ||
if sys.version[0] == "3": | ||
serverfile_dir = os.path.abspath(os.path.join(__file__, os.pardir)) | ||
logfile_path = os.path.abspath(os.path.join(__file__, os.pardir, "stderr_gunicorn.log")) | ||
subprocess.Popen(["gunicorn", "-D", "--log-level", "ERROR", | ||
"--chdir", serverfile_dir, | ||
"-k", "uvicorn.workers.UvicornWorker", | ||
"--error-logfile", logfile_path, | ||
"--bind", "unix:/tmp/gunicorn.sock", | ||
"test_asgi_server:app"]) | ||
time.sleep(5) | ||
with open(logfile_path, "r") as gunicorn_log_file: | ||
stderr_log = gunicorn_log_file.read() | ||
|
||
subprocess.Popen(["pkill", "-f", "gunicorn"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it would be better to kill exactly the pid that was created, in case there are other things running. But we might be able to create an entirely simpler test (we'll see once I can reproduce), so let's wait and see. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I guess you are right. Fortunately, Gunicorn can output the PID that launches, so can be retreived by Python and be killed. |
||
time.sleep(5) | ||
os.remove(logfile_path) | ||
else: | ||
stderr_log = "" | ||
self.assertEqual(stderr_log, "") | ||
|
||
if __name__ == "__main__": | ||
import nose | ||
nose.runmodule() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to declare these dependencies rather than running a command explicitly: https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html#test-requirements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I first thought about that. Unfortunately, apparently the test requirements cannot refer to a library that is not in the same conda channel as the project; and given that uvicorn is not available in the channel, it had no way of satisfying the requirement unless I explicitly conda installed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha ha, you can't win, sorry. No need to change then.
@jbednar @jlstevens can I change this project to use conda-forge?