cph-cachet / carp.core-kotlin

Infrastructure-agnostic framework for distributed data collection.
https://carp.cachet.dk/core/
MIT License
21 stars 3 forks source link

Fix: snapshot load for deployment with unregistered connected device #406

Closed Whathecode closed 2 years ago

Whathecode commented 2 years ago

Loading a StudyDeployment which had an unregistered connected device failed since to deploy a device (deviceDeployed), all required devices needed to be registered, and, when loading the snapshot deviceDeployed was called. This call failed after replaying the deployment's registration history and not all necessary devices were registered.

deviceDeployed was called as a way to ensure preconditions were checked. In this case, preconditions were checked incorrectly by doing so (a device can be deployed with connected devices unregistered after it has been deployed). The fix is to manipulate the StudyDeployment state directly, while still verifying snapshot correctness.

Also refactored test code a bit to remove redundant retrieval of the primary and connected device in the study protocols used for tests.

Whathecode commented 2 years ago

but the question is: It that firing those kind of even not necessary when manipulating StudyDeployment from snapshot?

@thaiphandinh The emitted events are actually omitted right before returning the snapshot since they are undesirable side effects. They represent changes made to the domain model while it was in memory. The events emitted as part of loading the snapshot are thus unwanted.