Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion burr/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

# Clear default handlers
setup_logging(logging.INFO)
OPEN_WHEN_READY_TIMEOUT_SECONDS = 5


def _command(command: str, capture_output: bool, addl_env: dict | None = None) -> str:
Expand Down Expand Up @@ -100,7 +101,7 @@ def _locate_package_root() -> Optional[str]:
def open_when_ready(check_url: str, open_url: str):
while True:
try:
response = requests.get(check_url)
response = requests.get(check_url, timeout=OPEN_WHEN_READY_TIMEOUT_SECONDS)
if response.status_code == 200:
webbrowser.open(open_url)
return
Expand Down
43 changes: 43 additions & 0 deletions tests/test_cli_open_when_ready.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from burr.cli import __main__ as cli_main


def test_open_when_ready_bounds_readiness_request(monkeypatch):
calls = []

class Response:
status_code = 200

def fake_get(url, **kwargs):
calls.append((url, kwargs))
return Response()

opened = []
monkeypatch.setattr(cli_main.requests, "get", fake_get)
monkeypatch.setattr(cli_main.webbrowser, "open", opened.append)

cli_main.open_when_ready("http://localhost:7241/health", "http://localhost:7241")

assert calls == [
(
"http://localhost:7241/health",
{"timeout": cli_main.OPEN_WHEN_READY_TIMEOUT_SECONDS},
)
]
assert opened == ["http://localhost:7241"]