Skip to content

Commit 998daa7

Browse files
author
Artem Korzhenevskii
committed
Add hoverfly startup timeout option
1 parent 26d6b0b commit 998daa7

File tree

6 files changed

+69
-17
lines changed

6 files changed

+69
-17
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
services:
1616
hoverfly:
17-
image: spectolabs/hoverfly:v1.3.6
17+
image: spectolabs/hoverfly:v1.3.7
1818
ports:
1919
- 8500:8500
2020
- 8888:8888

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [5.0.4] - 2023-01-28
8+
### Changed
9+
- Allow specifying hoverfly startup timeout
10+
- Increased default hoverfly startup timeout
11+
12+
## [5.0.3] - 2022-08-31
13+
### Changed
14+
- Bumped default Hoverfly image to 1.3.7 to support Apple silicon
15+
716
## [5.0.2] - 2022-03-28
817
### Changed
918
- Bumped default Hoverfly image to 1.3.6

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pytest_hoverfly"
3-
version = "5.0.3"
3+
version = "5.0.4"
44
description = "Simplify working with Hoverfly from pytest"
55
authors = ["Devops team at Wrike <[email protected]>"]
66
repository = "https://github.com/wrike/pytest-hoverfly"
@@ -21,9 +21,9 @@ docker = ">=5.0.3"
2121
typing_extensions = ">=3.7.4"
2222

2323
[tool.poetry.dev-dependencies]
24-
flake8 = ">=3.7.7"
24+
flake8 = "^5.0.4"
2525
toml = ">=0.10"
26-
isort = ">=5.3"
26+
isort = "^5.11"
2727
pytest-cov = ">=2.7.1"
2828
black = "^22.8.0"
2929

pytest_hoverfly/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def get_container(
7373
container_name: t.Optional[str] = None,
7474
ports: t.Optional[t.Dict[str, t.Optional[t.List[t.Dict[str, int]]]]] = None,
7575
image: str = IMAGE,
76-
timeout: float = 3.0,
76+
timeout: float = 30.0,
7777
docker_factory: t.Callable[[], DockerClient] = DockerClient.from_env,
7878
create_container_kwargs: t.Optional[t.Mapping[str, t.Any]] = None,
7979
):

pytest_hoverfly/pytest_hoverfly.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ def pytest_addoption(parser):
5959
type=Path,
6060
)
6161

62+
parser.addoption(
63+
"--hoverfly-start-timeout",
64+
dest="hoverfly_start_timeout",
65+
default=30.0,
66+
help=(
67+
"Timeout used while starting the container. "
68+
"It's used two times: waiting for ports to start accepting connections "
69+
"and waiting for endpoints to start handling requests."
70+
),
71+
type=float,
72+
)
73+
6274
parser.addoption(
6375
"--hoverfly-args",
6476
dest="hoverfly_args",
@@ -151,6 +163,7 @@ def hoverfly_instance(request) -> Hoverfly:
151163
yield from get_container(
152164
create_container_kwargs={"command": request.config.option.hoverfly_args},
153165
image=request.config.option.hoverfly_image,
166+
timeout=request.config.option.hoverfly_start_timeout,
154167
)
155168

156169

tests/test_pytest_hoverfly.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,18 @@ def test_hoverfly_decorator_recorder(testdir, tmpdir):
107107
# create a temporary pytest test file
108108
testdir.makepyfile(
109109
"""
110-
from unittest.mock import ANY
111-
import pytest
112-
import requests
113-
from pytest_hoverfly import hoverfly
114-
115-
@hoverfly('foaas_version_simulation', record=True)
116-
def test_stateful_simulation_recorder():
117-
resp = requests.get(
118-
'https://foaas.com/version',
119-
headers={'Accept': 'application/json'},
110+
from unittest.mock import ANY
111+
import requests
112+
from pytest_hoverfly import hoverfly
120113
121-
)
114+
@hoverfly('foaas_version_simulation', record=True)
115+
def test_stateful_simulation_recorder():
116+
resp = requests.get(
117+
'https://foaas.com/version',
118+
headers={'Accept': 'application/json'},
119+
)
122120
123-
assert resp.json() == {'message': ANY, 'subtitle': 'FOAAS'}
121+
assert resp.json() == {'message': ANY, 'subtitle': 'FOAAS'}
124122
"""
125123
)
126124

@@ -202,3 +200,35 @@ def test_lack_of_unintended_side_effects():
202200
assert "HTTPS_PROXY" not in os.environ
203201
assert "SSL_CERT_FILE" not in os.environ
204202
assert "REQUESTS_CA_BUNDLE" not in os.environ
203+
204+
205+
def test_timeout_option(testdir):
206+
"""Test timeout option is parsed correctly."""
207+
testdir.makepyfile(
208+
"""
209+
import requests
210+
from pytest_hoverfly import hoverfly
211+
212+
213+
@hoverfly(name='foaas_version_simulation')
214+
def test_timeout_parsing(request):
215+
resp = requests.get(
216+
'https://foaas.com/version',
217+
headers={'Accept': 'application/json'},
218+
)
219+
220+
assert resp.json() == {'message': 'Version 2.1.1', 'subtitle': 'FOAAS'}
221+
222+
# Hoverfly adds Hoverfly: Was-Here header
223+
assert 'Hoverfly' in resp.headers
224+
225+
assert request.config.option.hoverfly_start_timeout == 55.0
226+
"""
227+
)
228+
229+
# run all tests with pytest
230+
result = testdir.runpytest_subprocess(
231+
"--hoverfly-simulation-path", str(CURDIR / "simulations"), "--hoverfly-start-timeout", "55", "-vv"
232+
)
233+
234+
result.assert_outcomes(passed=1)

0 commit comments

Comments
 (0)