From 50383037a25c3778a0b5d692f46b421954bc401c Mon Sep 17 00:00:00 2001 From: Marcin Usielski <35992110+marcin-usielski@users.noreply.github.com> Date: Thu, 14 Oct 2021 15:49:23 +0200 Subject: [PATCH] Fix await_done in RunnerSingleThread (#423) * Fix await_done in RunnerSingleThread * codestyle * do not change timeout in ConnectionObserver during await_done * fix runner timeout for ConnectionObserver * fix * prearation for 1.32.2 --- CHANGELOG.md | 5 +++++ README.md | 2 +- docs/source/conf.py | 2 +- moler/runner_single_thread.py | 3 +-- setup.py | 2 +- test/cmd/unix/test_cmd_uptime.py | 38 +++++++++++++++++++++++++++----- 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57caee29c..9aba754c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## moler 1.32.2 + +### Improved +* Proper handled timeout in wait_for of RunnerSingleThread + ## moler 1.32.1 ### Improved diff --git a/README.md b/README.md index e3a7b9099..08f9d89e7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![image](https://img.shields.io/badge/pypi-v1.32.1-blue.svg)](https://pypi.org/project/moler/) +[![image](https://img.shields.io/badge/pypi-v1.32.2-blue.svg)](https://pypi.org/project/moler/) [![image](https://img.shields.io/badge/python-2.7%20%7C%203.6%20%7C%203.7%20%7C%203.8-blue.svg)](https://pypi.org/project/moler/) [![Build Status](https://travis-ci.org/nokia/moler.svg?branch=master)](https://travis-ci.org/nokia/moler) [![Coverage Status](https://coveralls.io/repos/github/nokia/moler/badge.svg?branch=master)](https://coveralls.io/github/nokia/moler?branch=master) diff --git a/docs/source/conf.py b/docs/source/conf.py index 0cd565224..1f456f9a8 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -24,7 +24,7 @@ author = 'Nokia' # The short X.Y version -version = '1.32.1' +version = '1.32.2' # The full version, including alpha/beta/rc tags release = 'stable' diff --git a/moler/runner_single_thread.py b/moler/runner_single_thread.py index 1632dbbc3..5d9d84e39 100644 --- a/moler/runner_single_thread.py +++ b/moler/runner_single_thread.py @@ -91,7 +91,6 @@ def wait_for(self, connection_observer, connection_observer_future, timeout=10.0 remain_time, msg = his_remaining_time("remaining", timeout=observer_timeout, from_start_time=start_time) self.logger.debug("go foreground: {} - {}".format(connection_observer, msg)) connection_observer.life_status.start_time = start_time - connection_observer.timeout = await_timeout self._execute_till_eol(connection_observer=connection_observer, max_timeout=max_timeout, await_timeout=await_timeout, @@ -210,7 +209,7 @@ def _wait_till_done(self, connection_observer, timeout, check_timeout): :param check_timeout: True to check timeout from connection_observer :return: True if done normally, False if timeout. """ - timeout_add = 10 + timeout_add = 0.1 term_timeout = 0 if connection_observer.life_status.terminating_timeout is None else \ connection_observer.life_status.terminating_timeout remain_time = timeout - (time.time() - connection_observer.life_status.start_time) + term_timeout + timeout_add diff --git a/setup.py b/setup.py index 34ebf240e..89cd7ae07 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name='moler', # Required - version='1.32.1', # Required + version='1.32.2', # Required description='Moler is library to help in building automated tests', # Required long_description=long_description, # Optional long_description_content_type='text/markdown', # Optional (see note above) diff --git a/test/cmd/unix/test_cmd_uptime.py b/test/cmd/unix/test_cmd_uptime.py index f1c85f995..a377e8588 100644 --- a/test/cmd/unix/test_cmd_uptime.py +++ b/test/cmd/unix/test_cmd_uptime.py @@ -3,17 +3,18 @@ Testing of uptime command. """ __author__ = 'Marcin Usielski' -__copyright__ = 'Copyright (C) 2018-2019, Nokia' +__copyright__ = 'Copyright (C) 2018-2021, Nokia' __email__ = 'marcin.usielski@nokia.com' import pytest +import time from moler.exceptions import CommandFailure from moler.exceptions import CommandTimeout +from moler.cmd.unix.uptime import Uptime def test_calling_uptime_returns_result_parsed_from_command_output(buffer_connection, command_output_and_expected_result): - from moler.cmd.unix.uptime import Uptime command_output, expected_result = command_output_and_expected_result buffer_connection.remote_inject_response([command_output]) uptime_cmd = Uptime(connection=buffer_connection.moler_connection) @@ -30,28 +31,53 @@ def test_calling_uptime_fails_unsupported_format(buffer_connection, command_unsu uptime_cmd() +def test_calling_uptime_timeout_with_long_timeout(buffer_connection): + uptime_cmd = Uptime(connection=buffer_connection.moler_connection) + long_timeout = 300 + uptime_cmd.terminating_timeout = 0.2 + uptime_cmd.start(timeout=long_timeout) + uptime_cmd.timeout = long_timeout + start_time = time.time() + with pytest.raises(CommandTimeout): + uptime_cmd.await_done(timeout=1) + end_time = time.time() + duration = end_time - start_time + assert duration < long_timeout/10 + + +def test_calling_uptime_timeout_with_short_timeout(buffer_connection): + uptime_cmd = Uptime(connection=buffer_connection.moler_connection) + short_timeout = 7 + uptime_cmd.terminating_timeout = 0.2 + uptime_cmd.start(timeout=short_timeout) + start_time = time.time() + with pytest.raises(CommandTimeout): + uptime_cmd.await_done() + end_time = time.time() + duration = end_time - start_time + assert duration < short_timeout + 1 + assert duration >= short_timeout + + def test_calling_uptime_timeout(buffer_connection): - from moler.cmd.unix.uptime import Uptime uptime_cmd = Uptime(connection=buffer_connection.moler_connection) uptime_cmd.terminating_timeout = 0.2 uptime_cmd.timeout = 0.2 with pytest.raises(CommandTimeout): uptime_cmd() + def test_uptime_returns_proper_command_string(buffer_connection): - from moler.cmd.unix.uptime import Uptime uptime_cmd = Uptime(buffer_connection.moler_connection) assert "uptime" == uptime_cmd.command_string def test_uptime_sends_with_enter(buffer_connection): - from moler.cmd.unix.uptime import Uptime uptime_cmd = Uptime(buffer_connection.moler_connection) uptime_cmd.send_command() def test_uptime_sends_without_enter(buffer_connection): - from moler.cmd.unix.uptime import Uptime uptime_cmd = Uptime(buffer_connection.moler_connection) uptime_cmd.newline_after_command_string = False uptime_cmd.send_command()