Skip to content

Commit

Permalink
feat: use tenacity to wait for notebook server
Browse files Browse the repository at this point in the history
  • Loading branch information
NohaIhab committed Sep 28, 2023
1 parent dc3ec5a commit 143628d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions jupyter-tensorflow-full/tests/test_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@
import os
import subprocess
import time
import requests
import tenacity
import yaml


@tenacity.retry(
stop=tenacity.stop_after_attempt(5),
wait=tenacity.wait_fixed(2)
)
def check_notebook_server_up(url):
response = requests.get(url)
response.raise_for_status() # Raise an exception if the request was unsuccessful
return response.text

def main():
"""Test running container and imports."""
rock = yaml.safe_load(Path("rockcraft.yaml").read_text())
Expand All @@ -24,11 +35,9 @@ def main():
container_id = subprocess.run(["docker", "run", "-d", "-p", "8888:8888", LOCAL_ROCK_IMAGE], stdout=subprocess.PIPE).stdout.decode('utf-8')
container_id = container_id[0:12]

# to ensure container is started
time.sleep(10)
# Try to reach the notebook server
output = check_notebook_server_up("http://0.0.0.0:8888/lab")

# retrieve notebook server URL
output = subprocess.run(["curl", "http://0.0.0.0:8888/lab"], stdout=subprocess.PIPE).stdout.decode('utf-8')
# cleanup
subprocess.run(["docker", "stop", f"{container_id}"])
subprocess.run(["docker", "rm", f"{container_id}"])
Expand Down
1 change: 1 addition & 0 deletions jupyter-tensorflow-full/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ deps =
juju<4.0
pytest
pytest-operator
tenacity
ops
commands =
# build and pack rock
Expand Down

0 comments on commit 143628d

Please sign in to comment.