Skip to content

Commit 9884534

Browse files
committed
Remove an unnecessary delay during unit test execution
1 parent 9cd5315 commit 9884534

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

operator-pipeline-images/tests/entrypoints/test_index.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
from functools import partial
12
from unittest.mock import MagicMock, patch
3+
24
import pytest
35

46
from operatorcert.entrypoints import index
@@ -16,22 +18,27 @@ def test_parse_indices() -> None:
1618

1719
@patch("operatorcert.iib.get_builds")
1820
def test_wait_for_results(mock_get_builds: MagicMock) -> None:
21+
wait = partial(
22+
index.wait_for_results,
23+
"https://iib.engineering.redhat.com",
24+
"some_batch_id",
25+
delay=0.1,
26+
timeout=0.5,
27+
)
1928

2029
# if the builds are in complete state
2130
mock_get_builds.return_value = {
2231
"items": [{"state": "complete", "batch": "some_batch_id"}]
2332
}
2433

25-
rsp = index.wait_for_results("https://iib.engineering.redhat.com", "some_batch_id")
26-
assert rsp["items"] == [{"state": "complete", "batch": "some_batch_id"}]
34+
assert wait()["items"] == [{"state": "complete", "batch": "some_batch_id"}]
2735

2836
# if the builds are in failed state without state history
2937
mock_get_builds.return_value = {
3038
"items": [{"state": "failed", "id": 1, "batch": "some_batch_id"}]
3139
}
3240

33-
rsp = index.wait_for_results("https://iib.engineering.redhat.com", "some_batch_id")
34-
assert rsp["items"] == [{"state": "failed", "id": 1, "batch": "some_batch_id"}]
41+
assert wait()["items"] == [{"state": "failed", "id": 1, "batch": "some_batch_id"}]
3542

3643
# if the builds are in failed state with state history
3744
mock_get_builds.return_value = {
@@ -45,8 +52,7 @@ def test_wait_for_results(mock_get_builds: MagicMock) -> None:
4552
]
4653
}
4754

48-
rsp = index.wait_for_results("https://iib.engineering.redhat.com", "some_batch_id")
49-
assert rsp["items"] == [
55+
assert wait()["items"] == [
5056
{
5157
"state": "failed",
5258
"id": 1,
@@ -63,8 +69,7 @@ def test_wait_for_results(mock_get_builds: MagicMock) -> None:
6369
]
6470
}
6571

66-
rsp = index.wait_for_results("https://iib.engineering.redhat.com", "some_batch_id")
67-
assert rsp["items"] == [
72+
assert wait()["items"] == [
6873
{"state": "failed", "id": 2, "batch": "some_batch_id"},
6974
{"state": "complete", "id": 1, "batch": "some_batch_id"},
7075
]
@@ -77,10 +82,7 @@ def test_wait_for_results(mock_get_builds: MagicMock) -> None:
7782
]
7883
}
7984

80-
rsp = index.wait_for_results(
81-
"https://iib.engineering.redhat.com", "some_batch_id", timeout=1
82-
)
83-
assert rsp == None
85+
assert wait() is None
8486

8587

8688
@patch("operatorcert.iib.add_builds")

0 commit comments

Comments
 (0)