anysystem 0.1.2

A framework for deterministic simulation and testing of distributed systems
Documentation
use std::env;
use std::rc::Rc;

use serde::Serialize;

use crate::{Message, Process, ProcessState, System};

use crate::python::PyProcessFactory;

fn build_system() -> (System, Rc<dyn ProcessState>) {
    let mut sys = System::new(0);
    sys.add_node("node");
    let proc_f = PyProcessFactory::new("tests/python/process.py", "TestProcess");
    let process = proc_f.build((), 1);
    let state = process.state().unwrap();
    sys.add_process("proc", Box::new(process), "node");
    (sys, state)
}

#[derive(Serialize)]
struct EmptyMessage {}

#[test]
fn test_set_state() {
    env::set_var("PYTHONPATH", "python");
    let (mut sys, proc_state) = build_system();

    // check that process stores valid data
    // and update inner state (with `tmp_value` member)
    sys.send_local_message("proc", Message::json("CHECK_STATE", &EmptyMessage {}));
    sys.step_until_no_events();

    // reset process state to initial
    sys.get_mut_node("node").unwrap().set_process_state("proc", proc_state);
    // check that process stores the same data as right after initialization
    sys.send_local_message("proc", Message::json("CHECK_STATE", &EmptyMessage {}));
    sys.step_until_no_events();
}