Add a test for `update_service`
Add a sqlite backed test for the `update_service` method
@@ -1143,6 +1143,76 @@ pub mod tests {
assert_eq!(get_last_commit_entry, Some(update_commit_entry));
}
+ /// Test that the scabbard store `update_service` operation is successful.
+ ///
+ /// 1. Add a service in the prepared state to the database
+ /// 2. Add a context to the database for the service that has a past due alarm
+ /// 3. Call `list_ready_services` and check that the service is not returned
+ /// 4. Attempt to use `update_service` the service to change the service state to finalized
+ /// 5. Call `list_ready_services` and check that the service is returned
+ #[test]
+ fn scabbard_store_update_service() {
+ let pool = create_connection_pool_and_migrate();
+
+ let store = DieselScabbardStore::new(pool);
+
+ let service_fqsi = FullyQualifiedServiceId::new_from_string("abcde-fghij::aa00")
+ .expect("creating FullyQualifiedServiceId from string 'abcde-fghij::aa00'");
+
+ let peer_service_id = ServiceId::new_random();
+
+ // service with finalized status
+ let service = ScabbardServiceBuilder::default()
+ .with_service_id(&service_fqsi)
+ .with_peers(&[peer_service_id.clone()])
+ .with_status(&ServiceStatus::Prepared)
+ .build()
+ .expect("failed to build service");
+
+ assert!(store.add_service(service.clone()).is_ok());
+
+ let coordinator_context = ContextBuilder::default()
+ .with_alarm(SystemTime::now())
+ .with_coordinator(service_fqsi.clone().service_id())
+ .with_epoch(1)
+ .with_participants(vec![Participant {
+ process: peer_service_id.clone(),
+ vote: None,
+ }])
+ .with_state(Scabbard2pcState::WaitingForStart)
+ .with_this_process(service_fqsi.clone().service_id())
+ .build()
+ .expect("failed to build context");
+
+ let context = ScabbardContext::Scabbard2pcContext(coordinator_context);
+
+ store
+ .add_consensus_context(&service_fqsi, context)
+ .expect("failed to add context to store");
+
+ let ready_services = store
+ .list_ready_services()
+ .expect("failed to list ready services");
+
+ // Check that the service is not returned yet because it is in the prepared state still
+ assert!(ready_services.is_empty());
+
+ let update_service = service
+ .into_builder()
+ .with_status(&ServiceStatus::Finalized)
+ .build()
+ .expect("failed to build update service");
+
+ assert!(store.update_service(update_service).is_ok());
+
+ let ready_services = store
+ .list_ready_services()
+ .expect("failed to list ready services");
+
+ // check that the service is returned because it is in the finalized state now
+ assert_eq!(&ready_services[0], &service_fqsi);
+ }
+
fn create_connection_pool_and_migrate() -> Pool<ConnectionManager<SqliteConnection>> {
let connection_manager = ConnectionManager::<SqliteConnection>::new(":memory:");
let pool = Pool::builder()
