RclexTesting.DSL.Services (RclexTesting (Experimental) v0.12.3)

Copy Markdown View Source

Mock ROS services, call services, and assert requests received by mocked services.

mock_service/3 registers a scenario-owned service implementation and records each request. Use call_service/3 for synchronous clients, then assert or refute recorded requests with expect_service_call/2 and refute_service_call/2.

Summary

Functions

Call a service synchronously and return the response.

Assert that the mocked service received at least one new request.

Assert that the mocked service received a request matching predicate.

Register a test service implementation on the scenario node.

Assert that no new request arrives on the mocked service within the timeout.

Assert that no request matching predicate arrives within the timeout.

Functions

call_service(service_name, service_type, request, opts \\ [])

@spec call_service(String.t(), module(), struct(), keyword()) :: struct()

Call a service synchronously and return the response.

Starts a service client on the scenario node on first use. Raises on timeout or connection failure.

response = call_service "/safety/check", SafetyCheck, %SafetyCheck.Request{}
response = call_service "/safety/check", SafetyCheck, %SafetyCheck.Request{}, timeout: 3_000

expect_service_call(service_name, service_type)

@spec expect_service_call(String.t(), module()) :: struct()

Assert that the mocked service received at least one new request.

Cursor-based: previous requests already matched by earlier assertions are skipped. Returns the matching request struct.

expect_service_call "/safety/check", SafetyCheck

expect_service_call(service_name, service_type, predicate)

@spec expect_service_call(String.t(), module(), (struct() -> boolean())) :: struct()

Assert that the mocked service received a request matching predicate.

expect_service_call "/safety/check", SafetyCheck,
  fn req -> req.robot_id == "hilda_1" end

mock_service(service_name, service_type, handler)

@spec mock_service(String.t(), module(), (struct() -> struct())) :: :ok

Register a test service implementation on the scenario node.

All incoming requests are recorded in the collector and forwarded to handler. Cleanup is automatic when the scenario ends.

mock_service "/safety/check", SafetyCheck,
  fn _req -> %SafetyCheck.Response{allowed: true} end

refute_service_call(service_name, service_type)

refute_service_call(service_name, service_type, opts)

@spec refute_service_call(String.t(), module(), keyword()) :: :ok

Assert that no new request arrives on the mocked service within the timeout.

refute_service_call "/delete_map", DeleteMap

refute_service_call(service_name, service_type, predicate, opts)

@spec refute_service_call(String.t(), module(), (struct() -> boolean()), keyword()) ::
  :ok

Assert that no request matching predicate arrives within the timeout.

refute_service_call "/delete_map", DeleteMap, fn req -> req.force == true end