Ensuring Channels Properly Close Themselves
This commit is contained in:
parent
5d9f2ce9e3
commit
cf46554922
|
@ -139,7 +139,10 @@ func (cc *ChatChannel) Packet(data []byte) {
|
|||
} else if ack := res.GetChatAcknowledge(); ack != nil {
|
||||
cc.Handler.ChatMessageAck(ack.GetMessageId(), ack.GetAccepted())
|
||||
}
|
||||
// XXX?
|
||||
}
|
||||
// We ignore invalid packets.
|
||||
return
|
||||
}
|
||||
// Close the channel if it is being misused
|
||||
cc.channel.CloseChannel()
|
||||
}
|
||||
|
|
|
@ -155,8 +155,8 @@ func (crc *ContactRequestChannel) Packet(data []byte) {
|
|||
err := proto.Unmarshal(data, response)
|
||||
if err == nil {
|
||||
crc.handleStatus(response.GetStatus().String())
|
||||
return
|
||||
}
|
||||
}
|
||||
crc.channel.SendMessage([]byte{})
|
||||
// Whatever happens we close the channel
|
||||
crc.channel.CloseChannel()
|
||||
}
|
||||
|
|
|
@ -139,7 +139,12 @@ func TestContactRequestPacket(t *testing.T) {
|
|||
contactRequestChannel.OpenOutboundResult(nil, cr)
|
||||
|
||||
ackp := messageBuilder.ReplyToContactRequest(1, "Accepted")
|
||||
closed := false
|
||||
channel.CloseChannel = func() { closed = true }
|
||||
contactRequestChannel.Packet(ackp)
|
||||
if closed == false {
|
||||
t.Errorf("Channel Should Have Been Closed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContactRequestRejected(t *testing.T) {
|
||||
|
@ -160,7 +165,12 @@ func TestContactRequestRejected(t *testing.T) {
|
|||
contactRequestChannel.OpenOutboundResult(nil, cr)
|
||||
|
||||
ackp := messageBuilder.ReplyToContactRequest(1, "Rejected")
|
||||
closed := false
|
||||
channel.CloseChannel = func() { closed = true }
|
||||
contactRequestChannel.Packet(ackp)
|
||||
if closed == false {
|
||||
t.Errorf("Channel Should Have Been Closed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContactRequestError(t *testing.T) {
|
||||
|
@ -181,7 +191,12 @@ func TestContactRequestError(t *testing.T) {
|
|||
contactRequestChannel.OpenOutboundResult(nil, cr)
|
||||
|
||||
ackp := messageBuilder.ReplyToContactRequest(1, "Error")
|
||||
closed := false
|
||||
channel.CloseChannel = func() { closed = true }
|
||||
contactRequestChannel.Packet(ackp)
|
||||
if closed == false {
|
||||
t.Errorf("Channel Should Have Been Closed")
|
||||
}
|
||||
}
|
||||
|
||||
func BuildOpenChannel(nickname string, message string) *Protocol_Data_Control.OpenChannel {
|
||||
|
|
Reference in New Issue