Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/viam/resource/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

from viam.proto.common import ResourceName
from viam.resource.base import ResourceBase
from viam.services.service_base import ServiceBase
from viam.resource.registry import Registry

from ..services.service_base import ServiceBase
from ..components.component_base import ComponentBase
from ..errors import DuplicateResourceError, ResourceNotFoundError

Expand Down Expand Up @@ -40,6 +41,8 @@ def register(self, component: ResourceBase):
Args:
component (ResourceBase): The component to register
"""
Registry.lookup_subtype(component.SUBTYPE) # confirm the subtype is registered in Registry

_BaseClasses = (ResourceBase, ComponentBase, ServiceBase)
rnames: Dict[ResourceName, ResourceBase] = {}
for subtype in component.__class__.mro():
Expand Down
16 changes: 15 additions & 1 deletion tests/test_component_service_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

import pytest
from grpclib import const
from grpclib.client import Channel

from viam.components.component_base import ComponentBase
from viam.errors import ResourceNotFoundError
from viam.operations import run_with_operation
from viam.resource.registry import Registry, ResourceRegistration
from viam.resource.rpc_client_base import ReconfigurableResourceRPCClientBase
from viam.resource.rpc_service_base import ResourceManager, ResourceRPCServiceBase
from viam.resource.types import Subtype

Expand All @@ -29,6 +33,10 @@ async def long_running(self, **kwargs) -> bool:
self.long_running_task_cancelled = False
return self.long_running_task_cancelled

class TestClient(TestComponent, ReconfigurableResourceRPCClientBase):
def __init__(self, name: str, channel: Channel):
...

class TestService(ResourceRPCServiceBase[TestComponent]):
RESOURCE_TYPE = TestComponent

Expand All @@ -37,9 +45,15 @@ async def long_running(self) -> bool:
return await component.long_running()

def __mapping__(self) -> Mapping[str, const.Handler]:
return {}
return {
"/TestService/long_running": const.Handler(self.long_running, const.Cardinality.UNARY_UNARY, "TestRequest", "TestResponse")
}

component = TestComponent("test")
with pytest.raises(ResourceNotFoundError):
service = TestService(ResourceManager([component]))

Registry.register_subtype(ResourceRegistration(TestComponent, TestService, lambda name, channel: TestClient(name, channel)))
service = TestService(ResourceManager([component]))

# Test bare functions
Expand Down