mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
We do need to include some kind of worker id in the server_name. If we don't do this and we start with multiple workers the internal QueueWorker won't work and multiple processes can pick up the same job if the web process is also a job handler.
39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
from gunicorn import SERVER_SOFTWARE
|
|
|
|
from galaxy.model.unittest_utils import GalaxyDataTestApp
|
|
from galaxy.tool_util.verify.wait import wait_on
|
|
from galaxy.web_stack import (
|
|
application_stack_class,
|
|
application_stack_instance,
|
|
GunicornApplicationStack,
|
|
WeblessApplicationStack,
|
|
)
|
|
|
|
|
|
def test_application_stack_class_factory(monkeypatch):
|
|
assert application_stack_class() == WeblessApplicationStack
|
|
monkeypatch.setenv("SERVER_SOFTWARE", SERVER_SOFTWARE)
|
|
assert application_stack_class() == GunicornApplicationStack
|
|
|
|
|
|
def test_application_stack_instance_factory(monkeypatch):
|
|
app = GalaxyDataTestApp()
|
|
monkeypatch.setenv("SERVER_SOFTWARE", SERVER_SOFTWARE)
|
|
stack_instance = application_stack_instance(app=app, config=app.config)
|
|
assert isinstance(stack_instance, GunicornApplicationStack)
|
|
assert stack_instance.name == "Gunicorn"
|
|
|
|
|
|
def test_application_stack_post_fork(monkeypatch):
|
|
app = GalaxyDataTestApp()
|
|
monkeypatch.setenv("SERVER_SOFTWARE", SERVER_SOFTWARE)
|
|
monkeypatch.setenv("GUNICORN_WORKER_ID", "100")
|
|
monkeypatch.setattr(GunicornApplicationStack, "do_post_fork", True)
|
|
stack_instance = application_stack_instance(app=app, config=app.config)
|
|
assert isinstance(stack_instance, GunicornApplicationStack)
|
|
stack_instance.register_postfork_function(lambda: stack_instance.set_postfork_server_name(app))
|
|
assert not app.config.server_name.endswith(".100")
|
|
stack_instance.late_postfork()
|
|
stack_instance.late_postfork_event.set()
|
|
wait_on(lambda: app.config.server_name.endswith(".100") or None, desc="server name to change", timeout=1, delta=0.1)
|