mirror of
https://github.com/django/daphne.git
synced 2025-07-11 08:22:17 +03:00
build endpoint description strings from runserver arguments before ca… (#434)
* build endpoint description strings from runserver arguments before calling dpahne server * Update Daphne requirement
This commit is contained in:
parent
577dfa1eee
commit
d9bff34428
|
@ -2,7 +2,7 @@ import datetime
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from daphne.server import Server
|
from daphne.server import Server, build_endpoint_description_strings
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management.commands.runserver import Command as RunserverCommand
|
from django.core.management.commands.runserver import Command as RunserverCommand
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
@ -75,11 +75,13 @@ class Command(RunserverCommand):
|
||||||
# Launch server in 'main' thread. Signals are disabled as it's still
|
# Launch server in 'main' thread. Signals are disabled as it's still
|
||||||
# actually a subthread under the autoreloader.
|
# actually a subthread under the autoreloader.
|
||||||
self.logger.debug("Daphne running, listening on %s:%s", self.addr, self.port)
|
self.logger.debug("Daphne running, listening on %s:%s", self.addr, self.port)
|
||||||
|
|
||||||
|
# build the endpoint description string from host/port options
|
||||||
|
endpoints = build_endpoint_description_strings(host=self.addr, port=self.port)
|
||||||
try:
|
try:
|
||||||
Server(
|
Server(
|
||||||
channel_layer=self.channel_layer,
|
channel_layer=self.channel_layer,
|
||||||
host=self.addr,
|
endpoints=endpoints,
|
||||||
port=int(self.port),
|
|
||||||
signal_handlers=not options['use_reloader'],
|
signal_handlers=not options['use_reloader'],
|
||||||
action_logger=self.log_action,
|
action_logger=self.log_action,
|
||||||
http_timeout=self.http_timeout,
|
http_timeout=self.http_timeout,
|
||||||
|
|
|
@ -88,12 +88,12 @@ class RunServerTests(TestCase):
|
||||||
@mock.patch('channels.management.commands.runworker.Worker')
|
@mock.patch('channels.management.commands.runworker.Worker')
|
||||||
def test_runserver_basic(self, mocked_worker, mocked_server, mock_stdout):
|
def test_runserver_basic(self, mocked_worker, mocked_server, mock_stdout):
|
||||||
# Django's autoreload util uses threads and this is not needed
|
# Django's autoreload util uses threads and this is not needed
|
||||||
# in the test envirionment.
|
# in the test environment.
|
||||||
# See:
|
# See:
|
||||||
# https://github.com/django/django/blob/master/django/core/management/commands/runserver.py#L105
|
# https://github.com/django/django/blob/master/django/core/management/commands/runserver.py#L105
|
||||||
call_command('runserver', '--noreload')
|
call_command('runserver', '--noreload')
|
||||||
mocked_server.assert_called_with(
|
mocked_server.assert_called_with(
|
||||||
port=8000,
|
endpoints=['tcp:port=8000:interface=127.0.0.1'],
|
||||||
signal_handlers=True,
|
signal_handlers=True,
|
||||||
http_timeout=60,
|
http_timeout=60,
|
||||||
host='127.0.0.1',
|
host='127.0.0.1',
|
||||||
|
@ -114,7 +114,7 @@ class RunServerTests(TestCase):
|
||||||
with self.settings(DEBUG=True, STATIC_URL='/static/'):
|
with self.settings(DEBUG=True, STATIC_URL='/static/'):
|
||||||
call_command('runserver', '--noreload')
|
call_command('runserver', '--noreload')
|
||||||
mocked_server.assert_called_with(
|
mocked_server.assert_called_with(
|
||||||
port=8000,
|
endpoints=['tcp:port=8000:interface=127.0.0.1'],
|
||||||
signal_handlers=True,
|
signal_handlers=True,
|
||||||
http_timeout=60,
|
http_timeout=60,
|
||||||
host='127.0.0.1',
|
host='127.0.0.1',
|
||||||
|
@ -126,7 +126,7 @@ class RunServerTests(TestCase):
|
||||||
|
|
||||||
call_command('runserver', '--noreload', 'localhost:8001')
|
call_command('runserver', '--noreload', 'localhost:8001')
|
||||||
mocked_server.assert_called_with(
|
mocked_server.assert_called_with(
|
||||||
port=8001,
|
endpoints=['tcp:port=8001:interface=127.0.0.1'],
|
||||||
signal_handlers=True,
|
signal_handlers=True,
|
||||||
http_timeout=60,
|
http_timeout=60,
|
||||||
host='localhost',
|
host='localhost',
|
||||||
|
@ -150,7 +150,7 @@ class RunServerTests(TestCase):
|
||||||
'''
|
'''
|
||||||
call_command('runserver', '--noreload', '--noworker')
|
call_command('runserver', '--noreload', '--noworker')
|
||||||
mocked_server.assert_called_with(
|
mocked_server.assert_called_with(
|
||||||
port=8000,
|
endpoints=['tcp:port=8000:interface=127.0.0.1'],
|
||||||
signal_handlers=True,
|
signal_handlers=True,
|
||||||
http_timeout=60,
|
http_timeout=60,
|
||||||
host='127.0.0.1',
|
host='127.0.0.1',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user