Skip to content

Commit 6a6ab98

Browse files
committed
Update test
1 parent b4efbff commit 6a6ab98

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

tests/unit/actor/test_actor_lifecycle.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sys
77
from datetime import datetime, timezone
88
from typing import TYPE_CHECKING, Any, cast
9+
from unittest import mock
910
from unittest.mock import AsyncMock, Mock
1011

1112
import pytest
@@ -150,9 +151,6 @@ async def handler(websocket: websockets.asyncio.server.ServerConnection) -> None
150151
port: int = ws_server.sockets[0].getsockname()[1] # type: ignore[index]
151152
monkeypatch.setenv(ActorEnvVars.EVENTS_WEBSOCKET_URL, f'ws://localhost:{port}')
152153

153-
# Make sure there is a charging manager that can be mocked
154-
Actor._get_charging_manager_implementation()
155-
156154
mock_run_client = Mock()
157155
mock_run_client.run.return_value.get = AsyncMock(
158156
side_effect=lambda: {
@@ -182,25 +180,24 @@ async def handler(websocket: websockets.asyncio.server.ServerConnection) -> None
182180
}
183181
)
184182

185-
monkeypatch.setattr(Actor._charging_manager, '_client', mock_run_client)
186-
187-
async with Actor:
188-
Actor.on(Event.PERSIST_STATE, log_persist_state)
189-
await asyncio.sleep(2)
190-
191-
for socket in ws_server.connections:
192-
await socket.send(
193-
json.dumps(
194-
{
195-
'name': 'migrating',
196-
'data': {
197-
'isMigrating': True,
198-
},
199-
}
183+
with mock.patch.object(Actor, 'new_client', return_value=mock_run_client):
184+
async with Actor:
185+
Actor.on(Event.PERSIST_STATE, log_persist_state)
186+
await asyncio.sleep(2)
187+
188+
for socket in ws_server.connections:
189+
await socket.send(
190+
json.dumps(
191+
{
192+
'name': 'migrating',
193+
'data': {
194+
'isMigrating': True,
195+
},
196+
}
197+
)
200198
)
201-
)
202199

203-
await asyncio.sleep(1)
200+
await asyncio.sleep(1)
204201

205202
assert len(persist_state_events_data) >= 3
206203

0 commit comments

Comments
 (0)