Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mock device extension #238

Merged
merged 110 commits into from
Apr 3, 2024
Merged

feat: mock device extension #238

merged 110 commits into from
Apr 3, 2024

Conversation

adamdama
Copy link
Contributor

@adamdama adamdama commented Sep 20, 2023

What

A ripple extension that supports setting up a WebSocket server to stand in for a device.
Thunder connection retries during boot

Why

To support unit, component and (contract) provider verification testing in a containerised or desktop environment without access to a hardware device.

Additionally to support development of certain features which do not rely on a real device to function but require certain responses from the lower layers of the software stack.

How

The premise of the mock device is simple. A WebSocket server with a registry of known requests and the responses we expect for each of those requests. When a request is made to the WebSocket server the incoming request is compared to the registry and if found the corresponding responses are sent back. If the request is unrecognised then nothing is sent back.

The extension is presented in two parts: a channel and a JSON-RPC extension. The channel holds the running WebSocket server that acts as the device and the JSON-RPC extension offers a control plane for the data within the server.

During extension loading a WebSocket server is started listening on the same port that the Thunder extension expects Thunder to be present on. In order to support this, connection retries have added to the Thunder SDK so that if the WebSocket server is not available immediately additional attempts to connect will be made.

The extension loads the initial state from a JSON file found in at a predetermined location. This is essential to get Ripple to boot up without crashing as certain requests and made to a device immediately after establishing the connection.

Once Ripple is running there are JSON-RPC methods which can be used to:

  • add or overwrite requests in the mock data registry
  • remove requests from the registry
  • emit an event not yet implmented

Test

Set up a manifest as per the included docs.
See docs for usage and try some of the patterns.

Checklist

  • I have self-reviewed this PR
  • I have added tests that prove the feature works or the fix is effective

core/sdk/src/api/mod.rs Outdated Show resolved Hide resolved
@satlead satlead self-assigned this Mar 7, 2024
@Nv-Delle1416 Nv-Delle1416 self-requested a review April 2, 2024 18:44
Copy link

github-actions bot commented Apr 2, 2024

Code Coverage

Package Line Rate Health
distributor.general.src 2%
core.main.src.service 30%
core.main.src.firebolt.handlers 2%
device.thunder_ripple_sdk.src.processors.events 0%
core.sdk.src.api.observability 48%
core.sdk.src.extn 83%
core.main.src 0%
core.main.src.state 19%
core.launcher.src 0%
device.thunder_ripple_sdk.src 16%
core.sdk.src.api.gateway 48%
core.main.src.processor 0%
core.main.src.bootstrap 0%
core.main.src.bootstrap.manifest 0%
core.main.src.bootstrap.extn 0%
core.main.src.processor.storage 0%
core.tdk.src.gateway 100%
core.sdk.src.extn.ffi 80%
core.main.src.service.extn 38%
device.thunder_ripple_sdk.src.client 78%
openrpc_validator.src 90%
device.thunder.src 0%
device.thunder_ripple_sdk.src.events 4%
device.thunder.src.bootstrap 0%
core.main.src.utils 13%
core.sdk.src.api.distributor 84%
core.sdk.src.framework 74%
core.sdk.src.api 66%
core.main.src.firebolt 1%
core.main.src.state.cap 44%
core.sdk.src.utils 53%
core.sdk.src.api.firebolt 50%
core.launcher.src.manager 7%
core.sdk.src.api.manifest 55%
core.main.src.service.apps 43%
core.sdk.src.extn.client 91%
core.sdk.src.api.device 59%
core.tdk.src.utils 0%
device.mock_device.src 52%
device.thunder_ripple_sdk.src.bootstrap 0%
device.thunder_ripple_sdk.src.processors 4%
Summary 35% (11910 / 33819)

Minimum allowed line rate is 33%

@satlead satlead merged commit afcb10c into main Apr 3, 2024
8 checks passed
@satlead satlead deleted the mock-device branch April 3, 2024 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Mock Device Extension
6 participants