diff --git a/src/runtime2/component/component.rs b/src/runtime2/component/component.rs index 53c362b7058caf4c05f741de40eb19604767d410..5e7bc0486149e21eb5da1081357caaf12687971d 100644 --- a/src/runtime2/component/component.rs +++ b/src/runtime2/component/component.rs @@ -433,8 +433,10 @@ pub(crate) fn default_handle_received_data_message( let _new_inbox_index = inbox_main.len(); if !received_port.messages.is_empty() { inbox_main.push(Some(received_port.messages.remove(0))); + inbox_backup.extend(received_port.messages.drain(..)); + } else { + inbox_main.push(None); } - inbox_backup.extend(received_port.messages.drain(..)); // Create a new port locally let mut new_port_state = received_port.state; diff --git a/src/runtime2/tests/transfer_ports.rs b/src/runtime2/tests/transfer_ports.rs index bd34250eec82e7e0e8eb49fbfdc5349a992ad680..133687f7f6bc76edc29ffa311376f4ef87327d78 100644 --- a/src/runtime2/tests/transfer_ports.rs +++ b/src/runtime2/tests/transfer_ports.rs @@ -74,10 +74,53 @@ fn test_transfer_precreated_port_with_foreign_peer_back_and_forth() { #[test] fn test_transfer_precreated_port_with_owned_peer_and_communication() { + compile_and_create_component(" + primitive port_sender(out> tx) { + channel a -> b; + sync put(tx, b); + sync put(a, 1337); + } + primitive port_receiver(in> rx) { + channel a -> b; // this is stupid, but we need to have a variable to use + sync b = get(rx); + u32 value = 0; + sync value = get(b); + while (value != 1337) {} + } + composite constructor() { + channel a -> b; + new port_sender(a); + new port_receiver(b); + } + ", "constructor", no_args()); } #[test] fn test_transfer_precreated_port_with_foreign_peer_and_communication() { + compile_and_create_component(" + primitive port_sender(out> tx, in to_send) { + sync put(tx, to_send); + } + + primitive message_transmitter(out tx) { + sync put(tx, 1337); + } + primitive port_receiver(in> rx) { + channel unused -> b; + sync b = get(rx); + u32 value = 0; + sync value = get(b); + while (value != 1337) {} + } + + composite constructor() { + channel port_tx -> port_rx; + channel value_tx -> value_rx; + new port_sender(port_tx, value_rx); + new port_receiver(port_rx); + new message_transmitter(value_tx); + } + ", "constructor", no_args()); } \ No newline at end of file