From 7e1dc225d7f4e9dd4722acdf998dc9d89fd3d0ee 2020-02-10 13:37:55 From: Christopher Esterhuyse Date: 2020-02-10 13:37:55 Subject: [PATCH] another test --- diff --git a/src/runtime/communication.rs b/src/runtime/communication.rs index 22469470de1c9cd16a9856b7d7eed5d9847d3f26..eeb6ea42b09ed0cf448c92ae3ae9ac458a31528f 100644 --- a/src/runtime/communication.rs +++ b/src/runtime/communication.rs @@ -323,8 +323,9 @@ impl Controller { Msg::CommMsg(CommMsg { contents, round_index }) => { log!( &mut self.inner.logger, - "recvd a round-appropriate CommMsg {:?}", - &contents + "recvd a round-appropriate CommMsg {:?} with key {:?}", + &contents, + received.recipient ); assert_eq!(round_index, self.inner.round_index); contents @@ -365,6 +366,11 @@ impl Controller { return self.end_round_with_decision(oracle); } CommMsgContents::SendPayload { payload_predicate, payload } => { + assert_eq!( + Getter, + self.inner.endpoint_exts.get(received.recipient).unwrap().info.polarity + ); + // message for some actor. Feed it to the appropriate actor // and then give them another chance to run. let subtree_id = ekey_to_holder.get(&received.recipient); @@ -512,16 +518,22 @@ impl MonoContext for MonoPContext<'_> { fn new_channel(&mut self) -> [Key; 2] { let [a, b] = Endpoint::new_memory_pair(); let channel_id = self.inner.channel_id_stream.next(); - let kp = self.inner.endpoint_exts.alloc(EndpointExt { - info: EndpointInfo { polarity: Putter, channel_id }, - endpoint: a, - }); - let kg = self.inner.endpoint_exts.alloc(EndpointExt { - info: EndpointInfo { polarity: Putter, channel_id }, - endpoint: b, - }); - self.ekeys.insert(kp); - self.ekeys.insert(kg); + + let mut clos = |endpoint, polarity| { + let endpoint_ext = + EndpointExt { info: EndpointInfo { polarity, channel_id }, endpoint }; + let ekey = self.inner.endpoint_exts.alloc(endpoint_ext); + let endpoint = &self.inner.endpoint_exts.get(ekey).unwrap().endpoint; + let token = Key::to_token(ekey); + self.inner + .messenger_state + .poll + .register(endpoint, token, Ready::readable(), PollOpt::edge()) + .expect("AAGAGGGGG"); + self.ekeys.insert(ekey); + ekey + }; + let [kp, kg] = [clos(a, Putter), clos(b, Getter)]; log!( &mut self.inner.logger, "!! MonoContext callback to new_channel. returning ekeys {:?}!", diff --git a/src/test/connector.rs b/src/test/connector.rs index 13561940914addbd2a98629c6d18215a69e8b545..d08a7c52d0b49f5879f2a1148f11cc8ab05f0e1d 100644 --- a/src/test/connector.rs +++ b/src/test/connector.rs @@ -519,22 +519,51 @@ fn alternator_2() { #[test] // PANIC TODO: eval::1536 -fn composite_chain() { +fn composite_chain_a() { // Check if composition works. Forward messages through long chains /* - Alice -->sync-->sync-->A|P-->sync-->sync--> Bob + Alice -->sync-->sync-->A|P-->sync--> Bob */ - static PDL : &[u8] = -b"primitive sync(in i, out o) { - while(true) synchronous { - if (fires(i)) put(o, get(i)); - } + let timeout = Duration::from_millis(1_500); + let addrs = [next_addr(), next_addr()]; + const N: usize = 1; + static MSG: &[u8] = b"SSS"; + assert!(run_connector_set(&[ + // + &|x| { + // Alice + x.configure(PDL, b"sync_2").unwrap(); + x.bind_port(0, Native).unwrap(); + x.bind_port(1, Active(addrs[0])).unwrap(); + x.connect(timeout).unwrap(); + for _ in 0..N { + x.put(0, MSG.to_vec()).unwrap(); + assert_eq!(0, x.sync(timeout).unwrap()); + } + }, + &|x| { + // Bob + x.configure(PDL, b"forward").unwrap(); + x.bind_port(0, Passive(addrs[0])).unwrap(); + x.bind_port(1, Native).unwrap(); + x.connect(timeout).unwrap(); + for _ in 0..N { + // get msg round + x.get(0).unwrap(); + assert_eq!(Ok(0), x.sync(timeout)); + assert_eq!(Ok(MSG), x.read_gotten(0)); + } + }, + ])); } -composite sync_2(in i, out o) { - channel x -> y; - new sync(i, x); - new sync(y, o); -}"; + +#[test] +// PANIC TODO: eval::1536 +fn composite_chain_b() { + // Check if composition works. Forward messages through long chains + /* + Alice -->sync-->sync-->A|P-->sync-->sync--> Bob + */ let timeout = Duration::from_millis(1_500); let addrs = [next_addr(), next_addr()]; const N: usize = 1; @@ -554,7 +583,7 @@ composite sync_2(in i, out o) { }, &|x| { // Bob - x.configure(PDL, b"sync").unwrap(); + x.configure(PDL, b"sync_2").unwrap(); x.bind_port(0, Passive(addrs[0])).unwrap(); x.bind_port(1, Native).unwrap(); x.connect(timeout).unwrap();