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.
Options
Every function in this module accepts an optional trailing keyword list:
:namespacethe namespace of the scenario node. Defaults to the namespace given toscenario/3, or"/".:qosaRclex.QoSprofile. If not specified,Rclex.QoS.profile_services_default/0is used.:introspectionenables service event publishing with:metadataor:contents, and:introspection_qosconfigures the service event publisher. Both default to the Rclex defaults.:timeouthow long to wait, in milliseconds. Defaults to5000.
Any option other than :timeout is forwarded verbatim to the underlying Rclex call, so options not listed here are supported too.
Summary
Functions
Call a service synchronously and return the response.
Assert that the mocked service received at least one new request.
expect_service_call/2 with either a predicate or options.
expect_service_call/3 with both a predicate and options.
Register a test service implementation on the scenario node.
Assert that no new request arrives on the mocked service within the timeout.
refute_service_call/2 with either a predicate or options.
Assert that no request matching predicate arrives within the timeout.
Functions
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_000opts
:timeouthow long to wait, in milliseconds. Defaults to5000.:namespacethe namespace of the scenario node. Defaults to the namespace given toscenario/3, or"/".:qosaRclex.QoSprofile. If not specified,Rclex.QoS.profile_services_default/0is used. Only applied when the client is started.:introspectionenables service event publishing with:metadataor:contents, and:introspection_qosconfigures the service event publisher. Both default to the Rclex defaults.
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/2 with either a predicate or options.
expect_service_call "/safety/check", SafetyCheck,
fn req -> req.robot_id == "hilda_1" end
expect_service_call "/safety/check", SafetyCheck, timeout: 10_000opts
:timeouthow long to wait, in milliseconds. Defaults to5000.:namespacethe namespace of the scenario node. Defaults to the namespace given toscenario/3, or"/".
expect_service_call/3 with both a predicate and options.
expect_service_call "/safety/check", SafetyCheck,
fn req -> req.robot_id == "hilda_1" end, timeout: 10_000
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
mock_service "/safety/check", SafetyCheck, handler,
qos: Rclex.QoS.profile_services_default(), introspection: :contentsopts
:namespacethe namespace of the scenario node. Defaults to the namespace given toscenario/3, or"/".:qosaRclex.QoSprofile. If not specified,Rclex.QoS.profile_services_default/0is used.:introspectionenables service event publishing with:metadataor:contents, and:introspection_qosconfigures the service event publisher. Both default to the Rclex defaults.
Assert that no new request arrives on the mocked service within the timeout.
refute_service_call "/delete_map", DeleteMap
refute_service_call "/delete_map", DeleteMap, timeout: 500opts
:timeouthow long to wait, in milliseconds. Defaults to200.:namespacethe namespace of the scenario node. Defaults to the namespace given toscenario/3, or"/".
refute_service_call/2 with either a predicate or options.
refute_service_call "/delete_map", DeleteMap, fn req -> req.force == true end
refute_service_call "/delete_map", DeleteMap, timeout: 500
Assert that no request matching predicate arrives within the timeout.
refute_service_call "/delete_map", DeleteMap, fn req -> req.force == true end