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

Emulate devices for testing #2258

Closed
blhoward2 opened this issue Apr 7, 2021 · 6 comments
Closed

Emulate devices for testing #2258

blhoward2 opened this issue Apr 7, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@blhoward2
Copy link
Collaborator

blhoward2 commented Apr 7, 2021

It would be helpful for testing downstream for the node to emulate various device classes and allow sending values through the actual library, including things like central scene notifications, basic sets, etc. Alarm values for devices would also be useful (door, water, etc.). This will lessen the need for actual devices to test downstream changes and ease development.

It would also be helpful for an automated pattern to also be able to be run, so that downstream can run automated tests against the emulated devices.

Ideally we would eventually emulate actual devices using data captured from the device, but as an initial step there should at least be a way to setup basic emulated devices of each class and to push through expected types of messages.

@raman325 - Anything to add?

@blhoward2 blhoward2 added the enhancement New feature or request label Apr 7, 2021
@blhoward2 blhoward2 added the help wanted Extra attention is needed label Apr 7, 2021
@blhoward2
Copy link
Collaborator Author

blhoward2 commented Apr 7, 2021

@billiaz @ahochsteger Any interest? This would need both some backend work and a nice UI.

@raman325
Copy link
Contributor

raman325 commented Apr 7, 2021

See zwave-js/zwave-js-server#171 for context. I'd like to add more test coverage to zwave-js-server (we have basically nothing now) so we need test data to work with. If zwave-js provides the data, presumably we can use that to build these tests

@AlCalzone
Copy link
Member

AlCalzone commented Apr 7, 2021

@raman325 my idea was that you can use the driver with a mocked serialport, like I do for end-to-end tests and send it the serial data that is received by devices. An example can be found here: https://github.com/zwave-js/node-zwave-js/blob/master/packages/zwave-js/src/lib/test/driver/receiveApplicationCommandHandlerBridge.test.ts

Enabling this will require a bit of work because right now that setup does not allow you to start from cache without passing in all capabilities by hand or replaying the interview.

Basically the necessary steps would then be:

  • Create a driver instance with a mock serialport ✔
  • Initialize that driver instance with a test network (one cached node) 🛠
  • Send the driver data, handle/test events on your end ✔

@raman325
Copy link
Contributor

raman325 commented Apr 7, 2021

that's helpful, thanks! Full disclosure, I have been using this project to learn TypeScript, and tests are something I haven't worked with yet. Everything you said makes sense, next step for me is to figure out how to implement it 🙂

@AlCalzone
Copy link
Member

The tricky part is here:

if (!this.options.skipInterview) {
// Interview the controller.
await this._controller.interview(initValueDBs, async () => {
// Try to restore the network information from the cache
if (process.env.NO_CACHE !== "true") {
await this.restoreNetworkStructureFromCache();
}
});
// No need to initialize databases if skipInterview is true, because it is only used in some
// Driver unit tests that don't need access to them
}

skips the entire communication with the controller during unit tests.
However that call is also responsible for populating the value DB from cache etc, so it will need to be refactored a bit.

@AlCalzone
Copy link
Member

This is actually supported since v10 and actively used in some integration tests I couldn't have done without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants