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

Client side improvements #77

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions talker/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion talker/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 40 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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)
7 changes: 6 additions & 1 deletion tests/uts/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down