Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests to cover new pubsub completion policy
  • Loading branch information
dippi committed Jul 4, 2021
commit 36bf77259e7ffb71dd1055dd7668d90aef5431a7
36 changes: 36 additions & 0 deletions src/client/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,40 @@ mod test {
assert_eq!(result[1], "test-message-2".into());
assert_eq!(result[2], "test-message-3".into());
}

#[tokio::test]
async fn test_connection_remains_open_after_unsubscription() {
let addr = "127.0.0.1:6379".parse().unwrap();
let pubsub = super::pubsub_connect(addr)
.await
.expect("Cannot connect to Redis");

let topic_messages = pubsub
.subscribe("test-topic")
.await
.expect("Cannot subscribe to topic");
drop(topic_messages);

pubsub
.subscribe("test-topic")
.await
.expect("Cannot subscribe to topic");
}
}

#[tokio::test]
async fn test_connection_is_closed_after_channel_is_dropped() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to do this test outside the test module, to have access to the private types. Is there a better way?

let addr = "127.0.0.1:6379".parse().unwrap();
let connection = connect_with_auth(&addr, None, None)
.await
.expect("Cannot connect to Redis");
let (out_tx, out_rx) = mpsc::unbounded();
let handle = tokio::spawn(async {
match PubsubConnectionInner::new(connection, out_rx).await {
Ok(_) => (),
Err(e) => log::error!("Pub/Sub error: {:?}", e),
}
});
drop(out_tx);
handle.await.expect("Complete");
}