Skip to content

Commit

Permalink
fix: Fixes the crashing dev mode (#218)
Browse files Browse the repository at this point in the history
* fix: Fixes the crashing dev mode

the dev mode was crashing as the properties were being treated as a function

* test(add-scope-in-tests): fix the need for the freeport dependency and add scopes
  • Loading branch information
sansyrox committed Jun 29, 2022
1 parent c5be17e commit 73d0cd6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion integration_tests/base_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ async def redirect_route(request):

if __name__ == "__main__":
ROBYN_URL = os.getenv("ROBYN_URL", "0.0.0.0")
ROBYN_PORT = int(os.getenv("ROBYN_PORT", "5000"))
app.add_header("server", "robyn")
current_file_path = pathlib.Path(__file__).parent.resolve()
app.add_directory(
Expand All @@ -180,4 +181,4 @@ async def redirect_route(request):
index_file="index.html",
)
app.startup_handler(startup_handler)
app.start(port=5000, url=ROBYN_URL)
app.start(port=ROBYN_PORT, url=ROBYN_URL)
9 changes: 2 additions & 7 deletions integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@

@pytest.fixture
def session():
subprocess.call(["yes | freeport 5000"], shell=True)
os.environ["ROBYN_URL"] = "127.0.0.1"
current_file_path = pathlib.Path(__file__).parent.resolve()
base_routes = os.path.join(current_file_path, "./base_routes.py")
process = subprocess.Popen(["python3", base_routes])
time.sleep(5)
yield
process.terminate()
del os.environ["ROBYN_URL"]


@pytest.fixture
def default_session():
subprocess.call(["yes | freeport 5000"], shell=True)
current_file_path = pathlib.Path(__file__).parent.resolve()
base_routes = os.path.join(current_file_path, "./base_routes.py")
process = subprocess.Popen(["python3", base_routes])
Expand All @@ -38,18 +35,16 @@ def global_session():
time.sleep(1)
yield
process.terminate()
del os.environ["ROBYN_URL"]


@pytest.fixture
@pytest.fixture(scope="session")
def dev_session():
subprocess.call(["yes | freeport 5000"], shell=True)
os.environ["ROBYN_URL"] = "127.0.0.1"
os.environ["ROBYN_PORT"] = "5001"
current_file_path = pathlib.Path(__file__).parent.resolve()
base_routes = os.path.join(current_file_path, "./base_routes.py")
process = subprocess.Popen(["python3", base_routes, "--dev"])
time.sleep(5)
yield
process.terminate()
del os.environ["ROBYN_URL"]

6 changes: 5 additions & 1 deletion integration_tests/test_base_url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
import os


def test_default_url_index_request(default_session):
Expand All @@ -10,17 +11,20 @@ def test_default_url_index_request(default_session):
def test_local_index_request(session):
BASE_URL = "http://127.0.0.1:5000"
res = requests.get(f"{BASE_URL}")
assert(os.getenv("ROBYN_URL") == "127.0.0.1")
assert(res.status_code == 200)


def test_global_index_request(global_session):
BASE_URL = "http://0.0.0.0:5000"
res = requests.get(f"{BASE_URL}")
assert(os.getenv("ROBYN_URL") == "0.0.0.0")
assert(res.status_code == 200)


def test_dev_index_request(dev_session):
BASE_URL = "http://0.0.0.0:5000"
BASE_URL = "http://127.0.0.1:5001"
res = requests.get(f"{BASE_URL}")
assert(os.getenv("ROBYN_PORT") == "5001")
assert(res.status_code == 200)

2 changes: 1 addition & 1 deletion robyn/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ def log_level(self):
@property
def is_dev(self):
_is_dev = self.args.dev
if _is_dev and (self.num_processes() != 1 or self.workers() != 1):
if _is_dev and (self.num_processes != 1 or self.workers != 1):
raise Exception("--processes and --workers shouldn't be used with --dev")
return _is_dev
1 change: 0 additions & 1 deletion robyn/test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ requests==2.26.0
uvloop==0.16.0
multiprocess==0.70.12.2
websockets==10.1
freeport==0.1.15

0 comments on commit 73d0cd6

Please sign in to comment.