Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable timeout setting for Python TestPipeline (#29646) #33866

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sdks/python/apache_beam/testing/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def __init__(
is_integration_test=False,
blocking=True,
additional_pipeline_args=None,
display_data=None):
display_data=None,
timeout=None):
"""Initialize a pipeline object for test.

Args:
Expand All @@ -96,6 +97,8 @@ def __init__(
included when construction the pipeline options object.
display_data (Dict[str, Any]): a dictionary of static data associated
with this pipeline that can be displayed when it runs.
timeout (float optional): The time in milliseconds to wait for the pipeline to finish
before raising a timeout exception. If None, will wait indefinitely.

Raises:
ValueError: if either the runner or options argument is not
Expand All @@ -107,6 +110,7 @@ def __init__(
self.options_list = (
self._parse_test_option_args(argv) + additional_pipeline_args)
self.blocking = blocking
self.timeout = timeout
if options is None:
options = PipelineOptions(self.options_list)
super().__init__(runner, options, display_data=display_data)
Expand All @@ -116,9 +120,9 @@ def run(self, test_runner_api=True):
test_runner_api=(
False if self.not_use_test_runner_api else test_runner_api))
if self.blocking:
state = result.wait_until_finish()
state = result.wait_until_finish(duration=self.timeout)
assert state in (PipelineState.DONE, PipelineState.CANCELLED), \
"Pipeline execution failed."
"Pipeline execution failed."

return result

Expand Down
Loading