diff --git a/src/test/connector.rs b/src/test/connector.rs index dd2a974d7d461b9da08714d7b38bd060559cdee7..7568053d6f051a511abc2e0e9b4151a8d330d8ad 100644 --- a/src/test/connector.rs +++ b/src/test/connector.rs @@ -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()); +}