• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

localstack / localstack / bf093a6f-b143-46ce-acf1-34f1a2978dc3

23 Jan 2025 09:34PM UTC coverage: 86.86% (-0.001%) from 86.861%
bf093a6f-b143-46ce-acf1-34f1a2978dc3

push

circleci

web-flow
S3: fix exception from ObjectLock retention (#12165)

4 of 4 new or added lines in 1 file covered. (100.0%)

92 existing lines in 6 files now uncovered.

61135 of 70383 relevant lines covered (86.86%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.65
/localstack-core/localstack/services/stepfunctions/asl/component/common/timeouts/timeout.py
1
import abc
1✔
2
from typing import Final, Optional
1✔
3

4
from localstack.aws.api.stepfunctions import (
1✔
5
    ExecutionFailedEventDetails,
6
    HistoryEventType,
7
)
8
from localstack.services.stepfunctions.asl.component.common.error_name.failure_event import (
1✔
9
    FailureEvent,
10
    FailureEventException,
11
)
12
from localstack.services.stepfunctions.asl.component.common.error_name.states_error_name import (
1✔
13
    StatesErrorName,
14
)
15
from localstack.services.stepfunctions.asl.component.common.error_name.states_error_name_type import (
1✔
16
    StatesErrorNameType,
17
)
18
from localstack.services.stepfunctions.asl.component.common.string.string_expression import (
1✔
19
    StringJSONata,
20
    StringSampler,
21
)
22
from localstack.services.stepfunctions.asl.component.eval_component import EvalComponent
1✔
23
from localstack.services.stepfunctions.asl.eval.environment import Environment
1✔
24
from localstack.services.stepfunctions.asl.eval.event.event_detail import EventDetails
1✔
25
from localstack.services.stepfunctions.asl.utils.json_path import NoSuchJsonPathError
1✔
26

27

28
class EvalTimeoutError(TimeoutError):
1✔
29
    pass
1✔
30

31

32
class Timeout(EvalComponent, abc.ABC):
1✔
33
    @abc.abstractmethod
1✔
34
    def is_default_value(self) -> bool: ...
1✔
35

36
    @abc.abstractmethod
1✔
37
    def _eval_seconds(self, env: Environment) -> int: ...
1✔
38

39
    def _eval_body(self, env: Environment) -> None:
1✔
40
        seconds = self._eval_seconds(env=env)
1✔
41
        env.stack.append(seconds)
1✔
42

43

44
class TimeoutSeconds(Timeout):
1✔
45
    DEFAULT_TIMEOUT_SECONDS: Final[int] = 99999999
1✔
46

47
    def __init__(self, timeout_seconds: int, is_default: Optional[bool] = None):
1✔
48
        if not isinstance(timeout_seconds, int) and timeout_seconds <= 0:
1✔
49
            raise ValueError(
×
50
                f"Expected non-negative integer for TimeoutSeconds, got '{timeout_seconds}' instead."
51
            )
52
        self.timeout_seconds: Final[int] = timeout_seconds
1✔
53
        self.is_default: Optional[bool] = is_default
1✔
54

55
    def is_default_value(self) -> bool:
1✔
56
        if self.is_default is not None:
1✔
57
            return self.is_default
1✔
58
        return self.timeout_seconds == self.DEFAULT_TIMEOUT_SECONDS
1✔
59

60
    def _eval_seconds(self, env: Environment) -> int:
1✔
61
        return self.timeout_seconds
1✔
62

63

64
class TimeoutSecondsJSONata(Timeout):
1✔
65
    string_jsonata: Final[StringJSONata]
1✔
66

67
    def __init__(self, string_jsonata: StringJSONata):
1✔
UNCOV
68
        super().__init__()
×
UNCOV
69
        self.string_jsonata = string_jsonata
×
70

71
    def is_default_value(self) -> bool:
1✔
UNCOV
72
        return False
×
73

74
    def _eval_seconds(self, env: Environment) -> int:
1✔
UNCOV
75
        self.string_jsonata.eval(env=env)
×
76
        # TODO: add snapshot tests to verify AWS's behaviour about non integer values.
UNCOV
77
        seconds = int(env.stack.pop())
×
UNCOV
78
        return seconds
×
79

80

81
class TimeoutSecondsPath(Timeout):
1✔
82
    string_sampler: Final[StringSampler]
1✔
83

84
    def __init__(self, string_sampler: StringSampler):
1✔
85
        self.string_sampler = string_sampler
1✔
86

87
    def is_default_value(self) -> bool:
1✔
88
        return False
1✔
89

90
    def _eval_seconds(self, env: Environment) -> int:
1✔
91
        try:
1✔
92
            self.string_sampler.eval(env=env)
1✔
93
        except NoSuchJsonPathError as no_such_json_path_error:
×
94
            json_path = no_such_json_path_error.json_path
×
95
            cause = f"Invalid path '{json_path}' : No results for path: $['{json_path[2:]}']"
×
96
            raise FailureEventException(
×
97
                failure_event=FailureEvent(
98
                    env=env,
99
                    error_name=StatesErrorName(typ=StatesErrorNameType.StatesRuntime),
100
                    event_type=HistoryEventType.ExecutionFailed,
101
                    event_details=EventDetails(
102
                        executionFailedEventDetails=ExecutionFailedEventDetails(
103
                            error=StatesErrorNameType.StatesRuntime.to_name(), cause=cause
104
                        )
105
                    ),
106
                )
107
            )
108
        seconds = env.stack.pop()
1✔
109
        if not isinstance(seconds, int) and seconds <= 0:
1✔
110
            raise ValueError(
×
111
                f"Expected non-negative integer for TimeoutSecondsPath, got '{seconds}' instead."
112
            )
113
        return seconds
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc