mirror of https://github.com/zulip/zulip.git
Allow running the dev server with the test database, on different ports
For use by frontend tests. (imported from commit c8f81b862963f00e5b5517ba05b2d1adcab6d78a)
This commit is contained in:
parent
31496e9189
commit
ed490c672f
|
@ -104,7 +104,8 @@ INITIAL_API_KEY_SALT = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
SHARED_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
SHARED_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
||||||
|
|
||||||
# Base URL of the Tornado server
|
# Base URL of the Tornado server
|
||||||
# We set it to None when running tests or populate_db.
|
# We set it to None when running backend tests or populate_db.
|
||||||
|
# We override the port number when running frontend tests.
|
||||||
TORNADO_SERVER = 'http://localhost:9993'
|
TORNADO_SERVER = 'http://localhost:9993'
|
||||||
|
|
||||||
# Make redirects work properly behind a reverse proxy
|
# Make redirects work properly behind a reverse proxy
|
||||||
|
|
|
@ -4,3 +4,4 @@ DATABASES["default"] = {"NAME": "zephyr/tests/zephyrdb.test",
|
||||||
"ENGINE": "django.db.backends.sqlite3",
|
"ENGINE": "django.db.backends.sqlite3",
|
||||||
"OPTIONS": { "timeout": 20, },}
|
"OPTIONS": { "timeout": 20, },}
|
||||||
|
|
||||||
|
TORNADO_SERVER = 'http://localhost:9983'
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
import optparse
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
from os import path
|
from os import path
|
||||||
|
@ -6,7 +7,8 @@ from os import path
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from twisted.web import proxy, server, resource
|
from twisted.web import proxy, server, resource
|
||||||
|
|
||||||
"""
|
parser = optparse.OptionParser(r"""
|
||||||
|
|
||||||
Starts the app listening on localhost, for local development.
|
Starts the app listening on localhost, for local development.
|
||||||
|
|
||||||
This script launches the Django and Tornado servers, then runs a reverse proxy
|
This script launches the Django and Tornado servers, then runs a reverse proxy
|
||||||
|
@ -17,16 +19,30 @@ which serves to both of them. After it's all up and running, browse to
|
||||||
Note that, while runserver and runtornado have the usual auto-restarting
|
Note that, while runserver and runtornado have the usual auto-restarting
|
||||||
behavior, the reverse proxy itself does *not* automatically restart on changes
|
behavior, the reverse proxy itself does *not* automatically restart on changes
|
||||||
to this file.
|
to this file.
|
||||||
"""
|
""")
|
||||||
|
|
||||||
proxy_port = 9991
|
parser.add_option('--test',
|
||||||
|
action='store_true', dest='test',
|
||||||
|
help='Use the testing database and ports')
|
||||||
|
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
base_port = 9991
|
||||||
|
manage_args = ''
|
||||||
|
if options.test:
|
||||||
|
base_port = 9981
|
||||||
|
manage_args = '--settings=humbug.test_settings'
|
||||||
|
|
||||||
|
proxy_port = base_port
|
||||||
|
django_port = base_port+1
|
||||||
|
tornado_port = base_port+2
|
||||||
proxy_host = 'localhost:%d' % (proxy_port,)
|
proxy_host = 'localhost:%d' % (proxy_port,)
|
||||||
|
|
||||||
os.chdir(path.join(path.dirname(__file__), '..'))
|
os.chdir(path.join(path.dirname(__file__), '..'))
|
||||||
|
|
||||||
procs = []
|
procs = []
|
||||||
for cmd in ['python manage.py runserver localhost:9992',
|
for cmd in ['python manage.py runserver %s localhost:%d' % (manage_args, django_port),
|
||||||
'python manage.py runtornado localhost:9993']:
|
'python manage.py runtornado %s localhost:%d' % (manage_args, tornado_port)]:
|
||||||
procs.append(subprocess.Popen(cmd, shell=True))
|
procs.append(subprocess.Popen(cmd, shell=True))
|
||||||
|
|
||||||
class Resource(resource.Resource):
|
class Resource(resource.Resource):
|
||||||
|
@ -34,9 +50,9 @@ class Resource(resource.Resource):
|
||||||
request.requestHeaders.setRawHeaders('X-Forwarded-Host', [proxy_host])
|
request.requestHeaders.setRawHeaders('X-Forwarded-Host', [proxy_host])
|
||||||
|
|
||||||
if request.uri in ['/json/get_updates', '/api/v1/get_messages']:
|
if request.uri in ['/json/get_updates', '/api/v1/get_messages']:
|
||||||
return proxy.ReverseProxyResource('localhost', 9993, '/'+name)
|
return proxy.ReverseProxyResource('localhost', tornado_port, '/'+name)
|
||||||
|
|
||||||
return proxy.ReverseProxyResource('localhost', 9992, '/'+name)
|
return proxy.ReverseProxyResource('localhost', django_port, '/'+name)
|
||||||
|
|
||||||
reactor.listenTCP(proxy_port, server.Site(Resource()), interface='127.0.0.1')
|
reactor.listenTCP(proxy_port, server.Site(Resource()), interface='127.0.0.1')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue