-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default timeout is 300 seconds. This can be changed using timeout parameter of: * conn.run(timeout=xy) * conn.exec(timeout=xy) * process.wait(timout=xy) Or in mhc.yaml by setting host.conn.timeout.
- Loading branch information
Showing
8 changed files
with
501 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
Timeouts | ||
######## | ||
|
||
By default, all command timeouts in 300 seconds, which should be more then | ||
sufficient for most use cases. This timeout ensures that code that runs | ||
unexpectedly long time (for example and unexpected user input is requested) is | ||
terminated gracefully. A command that hits the timeout raises | ||
:class:`~pytest_mh.conn.ProcessTimeoutError`. | ||
|
||
The default timeout can be overridden on multiple places: | ||
|
||
* Per host, in a configuration file, by setting ``timeout`` field in the | ||
``host.conn`` section | ||
* In a blocking calls using the ``timeout`` parameter, see | ||
:meth:`~pytest_mh.conn.Connection.run` and | ||
:meth:`~pytest_mh.conn.Connection.exec` | ||
* In a non-blocking calls using the ``timeout`` parameter on the | ||
:meth:`~pytest_mh.conn.Process.wait` method of a running process creating by | ||
:meth:`~pytest_mh.conn.Connection.async_run` or | ||
:meth:`~pytest_mh.conn.Connection.async_exec` | ||
|
||
.. code-block:: yaml | ||
:caption: Example: Overriding default timeout for the host | ||
hosts: | ||
- hostname: client1.test | ||
role: client | ||
conn: | ||
type: ssh | ||
host: 192.168.0.10 | ||
user: root | ||
password: Secret123 | ||
timeout: 600 # setting default timeout to 10 minutes | ||
.. code-block:: python | ||
:caption: Example: Setting specific timeout for single command | ||
@pytest.mark.topology(KnownTopology.Client) | ||
def test_timeout(client: Client): | ||
result = client.host.conn.run( | ||
""" | ||
echo 'stdout before'; | ||
>&2 echo 'stderr before'; | ||
sleep 15; | ||
echo 'stdout after'; | ||
>&2 echo 'stderr after' | ||
""", | ||
timeout=5, | ||
) | ||
@pytest.mark.topology(KnownTopology.Client) | ||
def test_timeout_async(client: Client): | ||
process = client.host.conn.async_run( | ||
""" | ||
echo 'stdout before'; | ||
>&2 echo 'stderr before'; | ||
sleep 15; | ||
echo 'stdout after'; | ||
>&2 echo 'stderr after' | ||
""" | ||
) | ||
process.wait(timeout=5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.