diff --git a/requirements_test.txt b/requirements_test.txt index 3030608..8767a95 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -2,5 +2,4 @@ pytest>=7.0.0 pytest-mock pytest-cov -flaky==3.7.0 mock-serial==0.0.1 \ No newline at end of file diff --git a/tests/test_connection.py b/tests/test_connection.py index ba28a82..8b540ad 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -3,7 +3,6 @@ from unittest import mock import pytest -from flaky import flaky from mock_serial import MockSerial from ynca.connection import YncaConnection, YncaProtocolStatus @@ -224,10 +223,6 @@ def test_protocol_status(mock_serial): def test_get_communication_log_items(mock_serial): with active_connection(mock_serial, communication_log_size=5) as connection: - raw_data = mock_serial.stub( - receive_bytes=b"@Subunit:Function=?\r\n", send_bytes=b"" - ) - time.sleep(SHORT_DELAY) logitems = connection.get_communication_log_items() assert len(logitems) == 4 # Send en received keep-alive @@ -238,8 +233,6 @@ def test_get_communication_log_items(mock_serial): assert len(logitems) == 5 # 1 dropped out due to size limit -# Flaky due to multiple threads needing to communicate. -@flaky(max_runs=5) def test_keep_alive(mock_serial): # Tweak the internal keep-alive interval to keep test short @@ -252,7 +245,7 @@ def test_keep_alive(mock_serial): message_callback = mock.MagicMock() connection.register_message_callback(message_callback) - time.sleep(1) + time.sleep(SHORT_DELAY) logitems = connection.get_communication_log_items() assert len(logitems) == 4 # Send en received keep-alive are logged diff --git a/ynca/connection.py b/ynca/connection.py index a614fca..8b8bee2 100644 --- a/ynca/connection.py +++ b/ynca/connection.py @@ -35,7 +35,7 @@ class YncaProtocol(serial.threaded.LineReader): # YNCA spec says standby timeout is 40 seconds, so use a shorter period to be on the safe side KEEP_ALIVE_INTERVAL = 30 - def __init__(self): + def __init__(self, communication_log_size=0): super().__init__() self.message_callback:Callable[[YncaProtocolStatus, str|None, str|None, str|None], None] self.disconnect_callback:Callable[[], None] | None @@ -44,7 +44,7 @@ def __init__(self): self._last_sent_command = None self.connected = False self._keep_alive_pending = False - self._communication_log_buffer: LogBuffer = LogBuffer(0) + self._communication_log_buffer: LogBuffer = LogBuffer(communication_log_size) self.num_commands_sent = 0 def connection_made(self, transport): @@ -222,7 +222,7 @@ def connect( try: self._serial = serial.serial_for_url(self._port) self._readerthread = serial.threaded.ReaderThread( - self._serial, YncaProtocol + self._serial, lambda: YncaProtocol(communication_log_size) ) self._readerthread.start() _, protocol = self._readerthread.connect() @@ -235,7 +235,6 @@ def connect( if self._protocol: self._protocol.message_callback = self._call_registered_message_callbacks self._protocol.disconnect_callback = disconnect_callback - self._protocol.set_communication_log_size(communication_log_size) def close(self): # Disconnect callback is for unexpected disconnects