Skip to content

Commit

Permalink
Fix await_done in RunnerSingleThread (#423)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
marcin-usielski authored Oct 14, 2021
1 parent c6248a9 commit 5038303
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## moler 1.32.2

### Improved
* Proper handled timeout in wait_for of RunnerSingleThread

## moler 1.32.1

### Improved
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
3 changes: 1 addition & 2 deletions moler/runner_single_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 32 additions & 6 deletions test/cmd/unix/test_cmd_uptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
Testing of uptime command.
"""
__author__ = 'Marcin Usielski'
__copyright__ = 'Copyright (C) 2018-2019, Nokia'
__copyright__ = 'Copyright (C) 2018-2021, Nokia'
__email__ = '[email protected]'

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)
Expand All @@ -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()
Expand Down

0 comments on commit 5038303

Please sign in to comment.