rstango 0.3.0

Implementation of the Tango distributed control system
Documentation
//! A device proxy, reaching a device served by a server of this process through the
//! protocol, as another process does, see [`ServerBuilder::local`].

use tango::error::ErrorKind;
use tango::server::{ClassDef, ServerBuilder};
use tango::testing::TestContext;


/// A device whose server is restarted, elsewhere: the proxy finds out its connection is
/// lost on the first request after, and finds the device again through the database once
/// it is back, the server being reached through the protocol and not directly, see
/// [`ServerBuilder::local`].
#[test]
fn reconnect() {

    let ctx = TestContext::new().unwrap();
    ctx.database().add_server("Motor/test", &[("test/motor/1", "Motor")]).unwrap();

    let serve = || ctx.serve(ServerBuilder::new("Motor", "test")
        .local(false)
        .class(ClassDef::<()>::new_default("Motor")).unwrap()).unwrap();

    serve();
    let dev = ctx.dev("test/motor/1");
    dev.ping().unwrap();
    let first = ctx.database().import_dev("test/motor/1").unwrap().itr;

    ctx.stop("Motor/test").unwrap();
    assert_eq!(dev.ping().unwrap_err().kind(), ErrorKind::DevNotConnected);
    assert!(dev.ping().is_err());

    serve();
    let second = ctx.database().import_dev("test/motor/1").unwrap().itr;
    assert_ne!(first.value(), second.value());
    dev.ping().unwrap();

}