use anyhow::Result;
use rogue_runtime::prelude::*;
rpc! {
struct ConsumeSelf {
id: InstanceId,
}
impl Identity for ConsumeSelf {
fn id(&self) -> &InstanceId {
&self.id
}
}
impl ConsumeSelf {
pub async fn new() -> Self {
Self {
id: InstanceId::new(),
}
}
pub async fn consume(self) {
}
}
}
#[tokio::test]
async fn test_consume_self() -> Result<()> {
let runtime = Runtime::create("consume_self_test".to_string()).await?;
match runtime
.execute_local(async move {
let test = ConsumeSelf::new().await;
let id = test.id();
let object_ref = ConsumeSelf::create("consume_self_test".into(), *id);
test.consume().await;
object_ref.consume().await;
Ok(())
})
.await
{
Ok(_) => {
panic!("instance should have been consumed");
}
Err(err) => {
assert_eq!(err.to_string(), "instance not found".to_string());
}
}
Ok(())
}