add unknown commands handling without breaking client connection (#26)

- fix client unsubscribe when subscribe list in the event of the
  received unsubscribe list is in a different order than subscribed
- add tests for subscribe and unsubscribe commands
- add tests for unknown command handling
This commit is contained in:
João Oliveira
2020-04-06 21:27:58 +01:00
committed by GitHub
parent e7f6a372f0
commit 922919a9d4
6 changed files with 137 additions and 14 deletions

View File

@@ -273,16 +273,16 @@ impl Subscriber {
}
// Read the response
for channel in &channels {
for _channel in &channels {
let response = self.read_response().await?;
match response {
Frame::Array(ref frame) => match frame.as_slice() {
[unsubscribe, uchannel]
if &unsubscribe.to_string() == "unsubscribe"
&& &uchannel.to_string() == channel =>
{
self.subscribed_channels.remove(&uchannel.to_string());
}
[unsubscribe, uchannel] if &unsubscribe.to_string() == "unsubscribe" => {
//unsubscribed channel should exist in the subscribed list at this point
if self.subscribed_channels.remove(&uchannel.to_string()) == false {
return Err(response.to_error());
}
},
_ => return Err(response.to_error()),
},
frame => return Err(frame.to_error()),