Skip to content

Commit

Permalink
Review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
j-bennet committed Jun 9, 2022
1 parent 3c5d405 commit 8be8c3c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
8 changes: 0 additions & 8 deletions it/basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,3 @@ def test_run_with_help(cfg):
output = process.run_subprocess_with_output(cmd)
expected = "usage: esrally [-h] [--version]"
assert expected in "\n".join(output)


@it.rally_in_mem
def test_run_without_http_connection(cfg):
cmd = it.esrally_command_line_for(cfg, "info --track geonames")
output = process.run_subprocess_with_output(cmd, {"http_proxy": "http://invalid"})
expected = "No Internet connection detected. Specify --offline"
assert expected in "\n".join(output)
4 changes: 2 additions & 2 deletions it/proxy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def assert_log_line_present(log_file, text):

@it.rally_in_mem
def test_run_with_direct_internet_connection(cfg, http_proxy, fresh_log_file):
assert it.esrally(cfg, "list tracks") == 0
assert it.esrally(cfg, "info --track geonames") == 0
assert_log_line_present(fresh_log_file, "Connecting directly to the Internet")


Expand All @@ -88,7 +88,7 @@ def test_anonymous_proxy_no_connection(cfg, http_proxy, fresh_log_file):
def test_authenticated_proxy_user_can_connect(cfg, http_proxy, fresh_log_file):
env = dict(os.environ)
env["http_proxy"] = http_proxy.authenticated_url
assert process.run_subprocess_with_logging(it.esrally_command_line_for(cfg, "list tracks"), env=env) == 0
assert process.run_subprocess_with_logging(it.esrally_command_line_for(cfg, "info --track geonames"), env=env) == 0
assert_log_line_present(fresh_log_file, f"Connecting via proxy URL [{http_proxy.authenticated_url}] to the Internet")
# authenticated proxy access is allowed
assert_log_line_present(fresh_log_file, "Detected a working Internet connection")
26 changes: 15 additions & 11 deletions tests/test_rally.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch

import pytest

from esrally import rally


@pytest.mark.parametrize(
"offline,probing_url,subcommand,expected",
"offline,has_conn,subcommand,expected",
[
(True, "https://github.com", "info", True),
(True, "http://invalid", "info", True),
(False, "https://github.com", "info", True),
(False, "http://invalid", "info", False),
(False, "http://github.com", "list", True),
(False, "http://invalid", "list", True),
# command that needs internet
(True, True, "info", True),
(True, False, "info", True),
(False, True, "info", True),
(False, False, "info", False),
# command that doesn't need internet
(True, True, "list", True),
(True, False, "list", True),
(False, True, "list", True),
(False, False, "list", True),
],
)
def test_ensure_internet_connection(offline, probing_url, subcommand, expected):
def test_ensure_internet_connection(offline, has_conn, subcommand, expected):
args = MagicMock(offline=offline, subcommand=subcommand)
logger = MagicMock()
cfg = MagicMock()
cfg.opts = MagicMock(return_value=probing_url)

assert rally.ensure_internet_connection(args, cfg, logger) == expected
with patch("esrally.rally.net.has_internet_connection", MagicMock(return_value=has_conn)):
assert rally.ensure_internet_connection(args, cfg, logger) == expected

0 comments on commit 8be8c3c

Please sign in to comment.