diff --git a/talker/command.py b/talker/command.py index 15130d9..bcc620c 100644 --- a/talker/command.py +++ b/talker/command.py @@ -644,8 +644,8 @@ def _decode_output(self, output, decode='utf8', safe=False): return ret def _request_outputs(self, pipeline): - pipeline.lrange(self._stdout_key, 0, -1) - pipeline.lrange(self._stderr_key, 0, -1) + pipeline.lrange(self._stdout_key, 0, -1, _cmd_id=self.job_id) + pipeline.lrange(self._stderr_key, 0, -1, _cmd_id=self.job_id) def _fetch_outputs(self): with self.talker.reactor.pipeline() as p: @@ -665,7 +665,7 @@ def _trim_outputs(self, stdout, stderr, pipeline=None): ((len_stdout, self._stdout_key), (len_stderr, self._stderr_key)): if data_len: - p.ltrim(redis_key, data_len, -1) + p.ltrim(redis_key, data_len, -1, _cmd_id=self.job_id) if pipeline is None: p.execute() diff --git a/talker/reactor.py b/talker/reactor.py index c306e20..98b1383 100644 --- a/talker/reactor.py +++ b/talker/reactor.py @@ -131,7 +131,7 @@ def _send(): return self._FALSE return res - res = wait(timeout, _send, sleep=0.01, progressbar=False, throw=False) + res = wait(timeout, _send, sleep=0.1, progressbar=False, throw=False) if res == self._FALSE: res = False return res diff --git a/tests/utils.py b/tests/utils.py index 2bfd7c9..433058c 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,8 +1,8 @@ import subprocess +from time import sleep, time from fakeredis import FakeStrictRedis -from time import sleep, time def get_container_id(container_name): return subprocess.check_output( @@ -93,3 +93,42 @@ def get_retcode(redis, job_id, timeout=1): def get_stdout(redis, job_id, timeout=1): return get_blpop_value(redis, 'result-{}-stdout'.format(job_id), timeout) + + +def configure_logging(): + import logging.config + import os + + log_folder = 'tmp' + if not os.path.isdir(log_folder): + os.makedirs(log_folder) + + configuration = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'detailed': { + 'format': '%(asctime)s|%(process)2s:%(threadName)-25s|%(name)-40s|%(levelname)-5s|' + '%(funcName)-30s |%(host)-35s|%(message)s', + } + }, + 'handlers': { + 'main_file': { + 'class': 'logging.handlers.RotatingFileHandler', + 'filename': os.path.join(log_folder, 'test.log'), + 'mode': 'w', + 'formatter': 'detailed', + 'level': 'DEBUG', + 'maxBytes': 2 ** 20 * 10, + 'delay': True, + 'encoding': 'utf-8', + } + }, + 'root': { + 'level': 'NOTSET', + 'handlers': ['main_file'] + }, + + } + + logging.config.dictConfig(configuration) diff --git a/tests/uts/test_client.py b/tests/uts/test_client.py index 3bd4a0b..6f6410b 100644 --- a/tests/uts/test_client.py +++ b/tests/uts/test_client.py @@ -14,7 +14,7 @@ from talker.client import get_talker from talker.errors import ClientCommandTimeoutError, CommandExecutionError, CommandPidTimeoutError, CommandAlreadyDone, \ TalkerServerTimeout, TalkerCommandLost, RedisConnectionError -from tests.utils import get_version +from tests.utils import get_version, configure_logging def get_uuid() -> str: @@ -50,6 +50,11 @@ def is_alive_mock(*args): class TestClient(unittest.TestCase): + @classmethod + def setUpClass(cls) -> None: + super().setUpClass() + configure_logging() + @patch('talker.client.get_redis', my_get_redis) def setUp(self): super().setUp()