Просмотр исходного кода

ci(device tests): update for new connection behaviour

Test was checking
 - non-persistent connection: full poll
 - wait 10.1s
 - check that next is a heartbeat and connection was made persistent

But since the first iteration was with a non-persistent connection, we
now expect a full poll the first time the persistent connection is used.

So add an extra step to trigger this full poll before the 10.1s wait.
Jason Rumney 1 неделя назад
Родитель
Сommit
adca1eedbf
1 измененных файлов с 7 добавлено и 4 удалено
  1. 7 4
      tests/test_device.py

+ 7 - 4
tests/test_device.py

@@ -601,13 +601,19 @@ async def test_async_receive(subject, mock_api, mocker):
     assert result == {"1": "INIT", "2": 2, "full_poll": True}
     assert result == {"1": "INIT", "2": 2, "full_poll": True}
     # Prepare for next round
     # Prepare for next round
     subject._cached_state = subject._cached_state | result
     subject._cached_state = subject._cached_state | result
+    mock_api().status.reset_mock()
     mock_api().set_socketPersistent.reset_mock()
     mock_api().set_socketPersistent.reset_mock()
+    print("getting second iteration...")
+    result = await loop.__anext__()
+    # Check that the connection was made persistent now that data has been
+    # returned
+    mock_api().set_socketPersistent.assert_called_once_with(True)
     mock_api().status.reset_mock()
     mock_api().status.reset_mock()
     # Wait long enough to force a heartbeat poll on the next iteration
     # Wait long enough to force a heartbeat poll on the next iteration
     subject._cached_state = subject._cached_state | {"updated_at": time()}
     subject._cached_state = subject._cached_state | {"updated_at": time()}
     await asyncio.sleep(10.1)
     await asyncio.sleep(10.1)
+    print("getting third iteration...")
     # Call the function under test
     # Call the function under test
-    print("getting second iteration...")
     result = await loop.__anext__()
     result = await loop.__anext__()
 
 
     # Check that a heartbeat poll was done
     # Check that a heartbeat poll was done
@@ -615,9 +621,6 @@ async def test_async_receive(subject, mock_api, mocker):
     mock_api().heartbeat.assert_called_once()
     mock_api().heartbeat.assert_called_once()
     mock_api().receive.assert_called_once()
     mock_api().receive.assert_called_once()
     assert result == {"1": "UPDATED", "full_poll": False}
     assert result == {"1": "UPDATED", "full_poll": False}
-    # Check that the connection was made persistent now that data has been
-    # returned
-    mock_api().set_socketPersistent.assert_called_once_with(True)
     # Prepare for next iteration
     # Prepare for next iteration
     subject._running = False
     subject._running = False
     mock_api().set_socketPersistent.reset_mock()
     mock_api().set_socketPersistent.reset_mock()