Skip to content

Commit

Permalink
Fix LoggingThread for python3
Browse files Browse the repository at this point in the history
Looking at the implementation of upload_task_log, it expects to
receive bytes as input, not text. Hence, the appropriate file-like
object is BytesIO, not StringIO.

Fixes release-engineering#66
  • Loading branch information
rohanpm committed Jan 7, 2019
1 parent e038778 commit 03f956a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 3 additions & 2 deletions kobo/worker/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import six

from six.moves import StringIO, queue
from six.moves import queue
from six.moves.xmlrpc_client import Fault
from six import BytesIO


__all__ = (
Expand Down Expand Up @@ -52,7 +53,7 @@ def run(self):
self._send_data = self._send_data.encode('utf-8')

try:
self._hub.upload_task_log(StringIO(self._send_data), self._task_id, "stdout.log", append=True)
self._hub.upload_task_log(BytesIO(self._send_data), self._task_id, "stdout.log", append=True)
self._send_time = now
self._send_data = ""
except Fault:
Expand Down
11 changes: 4 additions & 7 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

import time

import six
import unittest2 as unittest
import pytest

from six import BytesIO

from mock import Mock
from six.moves import StringIO

from kobo.worker.logger import LoggingThread, LoggingIO
from .utils import ArgumentIsInstanceOf


class TestLoggingThread(unittest.TestCase):

@pytest.mark.xfail(six.PY3, reason='Check issue #66 for more info (https://git.io/fxSc6).')
def test_upload_task_log_on_stop(self):
mock_hub = Mock()
thread = LoggingThread(mock_hub, 9999)
Expand All @@ -31,9 +29,8 @@ def test_upload_task_log_on_stop(self):
thread.stop()
self.assertFalse(thread.is_alive())
self.assertFalse(thread._running)
mock_hub.upload_task_log.assert_called_once_with(ArgumentIsInstanceOf(StringIO), 9999, 'stdout.log', append=True)
mock_hub.upload_task_log.assert_called_once_with(ArgumentIsInstanceOf(BytesIO), 9999, 'stdout.log', append=True)

@pytest.mark.xfail(six.PY3, reason='Check issue #66 for more info (https://git.io/fxSc6).')
def test_upload_task_log_after_some_time(self):
mock_hub = Mock()
thread = LoggingThread(mock_hub, 9999)
Expand All @@ -50,7 +47,7 @@ def test_upload_task_log_after_some_time(self):

# let the thread running for a while
time.sleep(.1)
mock_hub.upload_task_log.assert_called_once_with(ArgumentIsInstanceOf(StringIO), 9999, 'stdout.log', append=True)
mock_hub.upload_task_log.assert_called_once_with(ArgumentIsInstanceOf(BytesIO), 9999, 'stdout.log', append=True)

thread.stop()
self.assertFalse(thread.is_alive())
Expand Down

0 comments on commit 03f956a

Please sign in to comment.