49 lines
1.5 KiB
Rust
49 lines
1.5 KiB
Rust
use runa_client::LocalClient;
|
|
use runa_protocol::{Command, MessageDto, Reply};
|
|
|
|
#[test]
|
|
fn local_client_launches_server_and_operates_the_same_live_image() {
|
|
let mut client = LocalClient::spawn(env!("CARGO_BIN_EXE_runa-server"), &[] as &[&str]).unwrap();
|
|
|
|
let published = client
|
|
.request(Command::PublishBehavior {
|
|
name: "counter".to_owned(),
|
|
expected_revision: None,
|
|
source: "pub fn handle(state, kind, value) { (state + value, []) }".to_owned(),
|
|
})
|
|
.unwrap();
|
|
assert_eq!(published.request_id, "runa-client-1");
|
|
assert!(matches!(published.result, Ok(Reply::Behavior(_))));
|
|
|
|
let spawned = client
|
|
.request(Command::Spawn {
|
|
behavior_name: "counter".to_owned(),
|
|
state: 5,
|
|
mailbox_capacity: 2,
|
|
})
|
|
.unwrap();
|
|
assert_eq!(spawned.request_id, "runa-client-2");
|
|
assert_eq!(spawned.result, Ok(Reply::ActorSpawned { actor_id: 1 }));
|
|
|
|
client
|
|
.request(Command::Send {
|
|
actor_id: 1,
|
|
message: MessageDto { kind: 0, value: 7 },
|
|
})
|
|
.unwrap();
|
|
client
|
|
.request(Command::Tick {
|
|
ticks: 100,
|
|
instruction_budget: 10,
|
|
})
|
|
.unwrap();
|
|
let inspected = client
|
|
.request(Command::InspectActor { actor_id: 1 })
|
|
.unwrap();
|
|
assert!(matches!(
|
|
inspected.result,
|
|
Ok(Reply::Actor(actor)) if actor.state == 12
|
|
));
|
|
assert!(client.shutdown().unwrap().success());
|
|
}
|