Ver Fonte

ci: add delay before testing heatbeat interval

Now that the heartbeat interval is not reinitialised every time around
the loop, the test is incorrect. Since it is now based off a local
variable, the only way to test is either wait for the heartbeat
interval, or fake passage of time (which I am sure is possible in
pytest, but not wanting to do research right now).

Also whitespace cleanup for lint.
Jason Rumney há 2 meses atrás
pai
commit
a65259954a
2 ficheiros alterados com 3 adições e 4 exclusões
  1. 1 1
      custom_components/tuya_local/device.py
  2. 2 3
      tests/test_device.py

+ 1 - 1
custom_components/tuya_local/device.py

@@ -675,7 +675,7 @@ class TuyaLocalDevice(object):
                 self._api.set_socketPersistent(False)
                 if self._api.parent:
                     self._api.parent.set_socketPersistent(False)
-                    
+
                 if i + 1 == connections:
                     self._reset_cached_state()
                     self._api_working_protocol_failures += 1

+ 2 - 3
tests/test_device.py

@@ -602,9 +602,8 @@ async def test_async_receive(subject, mock_api, mocker):
     subject._cached_state = subject._cached_state | result
     mock_api().set_socketPersistent.reset_mock()
     mock_api().status.reset_mock()
-    # Set the updated_at back in time to force a heartbeat poll on the next iteration
-    subject._cached_state["updated_at"] = time() - 11
-
+    # Wait long enough to force a heartbeat poll on the next iteration
+    await asyncio.sleep(subject._heartbeat_interval + 0.1)
     # Call the function under test
     print("getting second iteration...")
     result = await loop.__anext__()