Skip to content

Commit

Permalink
try running with no parallelism
Browse files Browse the repository at this point in the history
  • Loading branch information
chejennifer committed Jul 12, 2024
1 parent 95e7096 commit eb51cb0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function run_webdriver_test {
fi
export FLASK_ENV=webdriver
export GOOGLE_CLOUD_PROJECT=datcom-website-dev
python3 -m pytest -n 5 --reruns 2 server/webdriver/tests/ ${@}
python3 -m pytest --reruns 2 server/webdriver/tests/ ${@}
deactivate
}

Expand Down
64 changes: 39 additions & 25 deletions shared/lib/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@
import os
import platform
import socket
import unittest
import warnings

from flask_testing import LiveServerTestCase

from nl_server.flask import create_app as create_nl_app
from server.__init__ import create_app as create_web_app
import server.lib.util as libutil


def find_open_port():
def find_open_port(skip_port: int | None = None):
for port in range(12000, 13000):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
if port == skip_port:
continue
res = sock.connect_ex(('localhost', port))
if res != 0:
return port


web_port = find_open_port()

nl_port = None
is_nl_mode = os.environ.get('ENABLE_MODEL') == 'true'
if is_nl_mode:
# Start NL server on an unused port, so multiple integration tests can
Expand All @@ -45,41 +49,51 @@ def find_open_port():
nl_port = 6060
should_start_nl_server = False
else:
nl_port = find_open_port()
nl_port = find_open_port(web_port)
should_start_nl_server = True


class NLWebServerTestCase(LiveServerTestCase):
def start_nl_server(port):
nl_app = create_nl_app()
nl_app.run(port=port, debug=False, use_reloader=False, threaded=True)


def start_web_server(web_port, nl_port=None):
if nl_port:
web_app = create_web_app(f'http://127.0.0.1:{nl_port}')
else:
web_app = create_web_app()
web_app.run(port=web_port, use_reloader=False)


class NLWebServerTestCase(unittest.TestCase):

@classmethod
def setUpClass(cls):
if is_nl_mode:
if should_start_nl_server:

def start_nl_server(app):
app.run(port=nl_port, debug=False, use_reloader=False, threaded=True)

nl_app = create_nl_app()
# Create a thread that will contain our running server
cls.proc = multiprocessing.Process(target=start_nl_server,
args=(nl_app,),
daemon=True)
cls.proc.start()
cls.nl_proc = multiprocessing.Process(target=start_nl_server,
args=(nl_port,),
daemon=True)
cls.nl_proc.start()
else:
cls.proc = None
cls.nl_proc = None
libutil.check_backend_ready(
['http://127.0.0.1:{}/healthz'.format(nl_port)])

# Start web app.
cls.web_proc = multiprocessing.Process(target=start_web_server,
args=(web_port, nl_port))
cls.web_proc.start()
libutil.check_backend_ready([f'http://127.0.0.1:{web_port}/healthz'])

def get_server_url(cls):
return f'http://localhost:{web_port}'

@classmethod
def tearDownClass(cls):
if is_nl_mode and cls.proc:
cls.proc.terminate()

def create_app(self):
"""Returns the Flask Server running Data Commons."""
if is_nl_mode:
app = create_web_app('http://127.0.0.1:{}'.format(nl_port))
else:
app = create_web_app()
app.config['LIVESERVER_PORT'] = 0
return app
if is_nl_mode and cls.nl_proc:
cls.nl_proc.terminate()
cls.web_proc.terminate()
5 changes: 2 additions & 3 deletions shared/lib/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ def set_up_macos_for_tests():
This code must only be run once per execution.
"""
if sys.version_info >= (3, 8) and sys.platform == "darwin":
multiprocessing.set_start_method("fork")
os.environ['no_proxy'] = '*'
multiprocessing.set_start_method("spawn")
os.environ['no_proxy'] = '*'

0 comments on commit eb51cb0

Please sign in to comment.