|
1 | 1 | import asyncio
|
2 | 2 | from typing import Any, Dict, List, Optional, Tuple
|
| 3 | +from unittest import mock |
3 | 4 |
|
4 | 5 | import pytest
|
5 | 6 | from google.protobuf.struct_pb2 import Struct, Value
|
|
39 | 40 | ResourceNamesRequest,
|
40 | 41 | ResourceNamesResponse,
|
41 | 42 | RobotServiceStub,
|
| 43 | + ShutdownRequest, |
| 44 | + ShutdownResponse, |
42 | 45 | Status,
|
43 | 46 | StopAllRequest,
|
44 | 47 | StopExtraParameters,
|
@@ -209,13 +212,20 @@ async def GetCloudMetadata(stream: Stream[GetCloudMetadataRequest, GetCloudMetad
|
209 | 212 | assert request is not None
|
210 | 213 | await stream.send_message(GET_CLOUD_METADATA_RESPONSE)
|
211 | 214 |
|
| 215 | + async def Shutdown(stream: Stream[ShutdownRequest, ShutdownResponse]) -> None: |
| 216 | + request = await stream.recv_message() |
| 217 | + assert request is not None |
| 218 | + response = ShutdownResponse() |
| 219 | + await stream.send_message(response) |
| 220 | + |
212 | 221 | manager = ResourceManager(resources)
|
213 | 222 | service = RobotService(manager)
|
214 | 223 | service.FrameSystemConfig = Config
|
215 | 224 | service.TransformPose = TransformPose
|
216 | 225 | service.DiscoverComponents = DiscoverComponents
|
217 | 226 | service.GetOperations = GetOperations
|
218 | 227 | service.GetCloudMetadata = GetCloudMetadata
|
| 228 | + service.Shutdown = Shutdown |
219 | 229 |
|
220 | 230 | return service
|
221 | 231 |
|
@@ -599,3 +609,21 @@ async def get_geometries(
|
599 | 609 |
|
600 | 610 | await client.close()
|
601 | 611 | Registry._SUBTYPES[Arm.SUBTYPE].create_rpc_client = old_create_client
|
| 612 | + |
| 613 | + @pytest.mark.asyncio |
| 614 | + async def test_shutdown(self, service: RobotService): |
| 615 | + async with ChannelFor([service]) as channel: |
| 616 | + |
| 617 | + async def shutdown_client_mock(self): |
| 618 | + return await self._client.Shutdown(ShutdownRequest()) |
| 619 | + |
| 620 | + client = await RobotClient.with_channel(channel, RobotClient.Options()) |
| 621 | + |
| 622 | + with mock.patch("viam.robot.client.RobotClient.shutdown") as shutdown_mock: |
| 623 | + shutdown_mock.return_value = await shutdown_client_mock(client) |
| 624 | + shutdown_response = await client.shutdown() |
| 625 | + |
| 626 | + assert shutdown_response == ShutdownResponse() |
| 627 | + shutdown_mock.assert_called_once() |
| 628 | + |
| 629 | + await client.close() |
0 commit comments