Skip to content

Commit fc82e95

Browse files
glados-vermacopybara-github
authored andcommitted
Update documentation for the default repeat limit, add constant for retrying "forever".
Originally the default was to repeat forever, which was changed to 3 at some point, without updating the documentation. FUTURE_COPYBARA_INTEGRATE_REVIEW=#1176 from google:dependabot/pip/pip-9d732ab251 f1af8f8 PiperOrigin-RevId: 691477516
1 parent e980042 commit fc82e95

3 files changed

Lines changed: 67 additions & 4 deletions

File tree

openhtf/core/phase_descriptor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import logging
2525
import os.path
2626
import pdb
27+
import sys
2728
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Set, Text, TYPE_CHECKING, Type, Union
2829

2930
import attr
@@ -43,6 +44,10 @@
4344
if TYPE_CHECKING:
4445
from openhtf.core import test_state # pylint: disable=g-import-not-at-top
4546

47+
48+
DEFAULT_REPEAT_LIMIT = 3
49+
MAX_REPEAT_LIMIT = sys.maxsize
50+
4651
_LOGGER = logging.getLogger(__name__)
4752

4853

@@ -111,8 +116,9 @@ class PhaseOptions(object):
111116
repeat_on_measurement_fail: If true, force phase with failed
112117
measurements to repeat up to repeat_limit times.
113118
repeat_on_timeout: If consider repeat on phase timeout, default is No.
114-
repeat_limit: Maximum number of repeats. None indicates a phase will be
115-
repeated infinitely as long as PhaseResult.REPEAT is returned.
119+
repeat_limit: Maximum number of repeats. DEFAULT_REPEAT_LIMIT applies if
120+
this is set to None. MAX_REPEAT_LIMIT can be used to repeat the phase
121+
virtually forever, as long as PhaseResult.REPEAT is returned.
116122
run_under_pdb: If True, run the phase under the Python Debugger (pdb). When
117123
setting this option, increase the phase timeout as well because the
118124
timeout will still apply when under the debugger.

openhtf/core/phase_executor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
from openhtf.core import test_state as htf_test_state # pylint: disable=g-import-not-at-top
5252

5353
DEFAULT_PHASE_TIMEOUT_S = 3 * 60
54-
DEFAULT_RETRIES = 3
5554
_JOIN_TRY_INTERVAL_SECONDS = 3
5655

5756
ARG_PARSER = argv.module_parser()
@@ -279,7 +278,9 @@ def execute_phase(
279278
requested and successfully ran for this phase execution.
280279
"""
281280
repeat_count = 1
282-
repeat_limit = (phase.options.repeat_limit or DEFAULT_RETRIES)
281+
repeat_limit = (
282+
phase.options.repeat_limit or phase_descriptor.DEFAULT_REPEAT_LIMIT
283+
)
283284
while not self._stopping.is_set():
284285
is_last_repeat = repeat_count >= repeat_limit
285286
phase_execution_outcome, profile_stats = self._execute_phase_once(

test/core/phase_executor_test.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Unit tests for phase_executor module."""
16+
17+
import unittest
18+
19+
import openhtf
20+
from openhtf.core import phase_descriptor
21+
22+
23+
class PhaseExecutorTest(unittest.TestCase):
24+
25+
def _run_repeating_phase(self, phase_options, expected_call_count):
26+
call_count = 0
27+
28+
@phase_options
29+
def repeating_phase():
30+
nonlocal call_count
31+
call_count += 1
32+
if call_count < phase_descriptor.DEFAULT_REPEAT_LIMIT + 1:
33+
return phase_descriptor.PhaseResult.REPEAT
34+
return phase_descriptor.PhaseResult.STOP
35+
36+
test = openhtf.Test(repeating_phase)
37+
test.execute()
38+
self.assertEqual(call_count, expected_call_count)
39+
40+
def test_execute_phase_with_repeat_limit_unspecified_uses_default_limit(self):
41+
self._run_repeating_phase(
42+
openhtf.PhaseOptions(),
43+
expected_call_count=phase_descriptor.DEFAULT_REPEAT_LIMIT,
44+
)
45+
46+
def test_execute_phase_with_repeat_limit_none_uses_default_limit(self):
47+
self._run_repeating_phase(
48+
openhtf.PhaseOptions(repeat_limit=None),
49+
expected_call_count=phase_descriptor.DEFAULT_REPEAT_LIMIT,
50+
)
51+
52+
def test_execute_phase_with_repeat_limit_max_exceeds_default_limit(self):
53+
self._run_repeating_phase(
54+
openhtf.PhaseOptions(repeat_limit=phase_descriptor.MAX_REPEAT_LIMIT),
55+
expected_call_count=phase_descriptor.DEFAULT_REPEAT_LIMIT + 1,
56+
)

0 commit comments

Comments
 (0)