Changeset - 58e19b42641f
[Not reviewed]
0 1 0
Hans-Dieter Hiep - 5 years ago 2020-02-04 17:26:03
hdh@cwi.nl
Add negative connector test
1 file changed with 55 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/test/connector.rs
Show inline comments
 
@@ -9,6 +9,7 @@ use test_generator::test_resources;
 

	
 
use crate::common::*;
 
use crate::runtime::*;
 
use crate::runtime::errors::*;
 

	
 
#[test]
 
fn incremental() {
 
@@ -50,7 +51,7 @@ fn incremental() {
 
}
 

	
 
#[test]
 
fn duo() {
 
fn duo_positive() {
 
    let timeout = Duration::from_millis(1_500);
 
    let addrs = ["127.0.0.1:7012".parse().unwrap(), "127.0.0.1:7013".parse().unwrap()];
 
    let a = thread::spawn(move || {
 
@@ -104,3 +105,56 @@ fn duo() {
 
    handle(a.join());
 
    handle(b.join());
 
}
 

	
 
#[test]
 
fn duo_negative() {
 
    let timeout = Duration::from_millis(500);
 
    let addrs = ["127.0.0.1:7012".parse().unwrap(), "127.0.0.1:7013".parse().unwrap()];
 
    let a = thread::spawn(move || {
 
        let mut x = Connector::Unconfigured(Unconfigured { controller_id: 0 });
 
        x.configure(b"
 
        primitive main(out a, out b) {
 
            synchronous {}
 
            synchronous {
 
                msg m = create(0);
 
                put(a, m); // fires a on second round
 
            }
 
        }").unwrap();
 
        x.bind_port(0, PortBinding::Passive(addrs[0])).unwrap();
 
        x.bind_port(1, PortBinding::Passive(addrs[1])).unwrap();
 
        x.connect(timeout).unwrap();
 
        assert_eq!(0, x.sync(timeout).unwrap());
 
        match x.sync(timeout) {
 
            Err(SyncErr::Timeout) => {}
 
            x => unreachable!("{:?}", x)
 
        }
 
    });
 
    let b = thread::spawn(move || {
 
        let mut x = Connector::Unconfigured(Unconfigured { controller_id: 1 });
 
        x.configure(b"
 
        primitive main(in a, in b) {
 
            while (true) {
 
                synchronous {
 
                    if (fires(a)) {
 
                        get(a);
 
                    }
 
                }
 
                synchronous {
 
                    if (fires(b)) { // never fire a on even round
 
                        get(b);
 
                    }
 
                }
 
            }
 
        }").unwrap();
 
        x.bind_port(0, PortBinding::Active(addrs[0])).unwrap();
 
        x.bind_port(1, PortBinding::Active(addrs[1])).unwrap();
 
        x.connect(timeout).unwrap();
 
        assert_eq!(0, x.sync(timeout).unwrap());
 
        match x.sync(timeout) {
 
            Err(SyncErr::Timeout) => {}
 
            x => unreachable!("{:?}", x)
 
        }
 
    });
 
    handle(a.join());
 
    handle(b.join());
 
}
0 comments (0 inline, 0 general)