Skip to content

Commit

Permalink
Remove delivery time from membership
Browse files Browse the repository at this point in the history
  • Loading branch information
pool2win committed Sep 13, 2024
1 parent 2c5958c commit 4db8b24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Node {
bind_address: bind_address.clone(),
static_key_pem: String::new(),
delivery_timeout: 500,
membership_handle: MembershipHandle::start(500, bind_address).await,
membership_handle: MembershipHandle::start(bind_address).await,
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/node/membership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ pub enum MembershipMessage {
pub(crate) struct MembershipActor {
members: ReliableSenderMap,
receiver: mpsc::Receiver<MembershipMessage>,
delivery_timeout: u64,
}

impl MembershipActor {
pub fn start(receiver: mpsc::Receiver<MembershipMessage>, delivery_timeout: u64) -> Self {
pub fn start(receiver: mpsc::Receiver<MembershipMessage>) -> Self {
Self {
members: HashMap::default(),
receiver,
delivery_timeout,
}
}

Expand Down Expand Up @@ -90,9 +88,9 @@ pub(crate) struct MembershipHandle {
}

impl MembershipHandle {
pub async fn start(delivery_timeout: u64, node_id: String) -> Self {
pub async fn start(node_id: String) -> Self {
let (sender, receiver) = mpsc::channel(32);
let actor = MembershipActor::start(receiver, delivery_timeout);
let actor = MembershipActor::start(receiver);
tokio::spawn(run_membership_actor(actor));
Self { sender }
}
Expand Down Expand Up @@ -150,7 +148,7 @@ mod tests {

#[tokio::test]
async fn it_should_create_membership_add_and_remove_members() {
let membership_handle = MembershipHandle::start(500, "localhost".to_string()).await;
let membership_handle = MembershipHandle::start("localhost".to_string()).await;
let reliable_sender_handle = ReliableSenderHandle::default();
let reliable_sender_handle_2 = ReliableSenderHandle::default();

Expand All @@ -170,7 +168,7 @@ mod tests {

#[tokio::test]
async fn it_should_result_in_error_when_removing_non_member() {
let membership_handle = MembershipHandle::start(500, "localhost".to_string()).await;
let membership_handle = MembershipHandle::start("localhost".to_string()).await;

assert!(membership_handle
.remove_member("localhost22".to_string())
Expand All @@ -180,15 +178,15 @@ mod tests {

#[tokio::test]
async fn it_should_return_members_as_empty_vec() {
let membership_handle = MembershipHandle::start(500, "localhost".to_string()).await;
let membership_handle = MembershipHandle::start("localhost".to_string()).await;

let reliable_senders = membership_handle.get_members().await;
assert!(reliable_senders.unwrap().is_empty());
}

#[tokio::test]
async fn it_should_return_members_as_vec() {
let membership_handle = MembershipHandle::start(500, "localhost".to_string()).await;
let membership_handle = MembershipHandle::start("localhost".to_string()).await;
let mut reliable_sender_handle = ReliableSenderHandle::default();
reliable_sender_handle
.expect_clone()
Expand Down

0 comments on commit 4db8b24

Please sign in to comment.