Merge pull request #2208 from lucas-clemente/fix-stream-deletion-errors

fix error message for stream deletion errors
This commit is contained in:
Marten Seemann
2019-11-08 17:56:10 +07:00
committed by GitHub
10 changed files with 36 additions and 16 deletions

View File

@@ -139,14 +139,14 @@ func (m *streamsMap) DeleteStream(id protocol.StreamID) error {
switch id.Type() {
case protocol.StreamTypeUni:
if id.InitiatedBy() == m.perspective {
return m.outgoingUniStreams.DeleteStream(num)
return convertStreamError(m.outgoingUniStreams.DeleteStream(num), protocol.StreamTypeUni, m.perspective)
}
return m.incomingUniStreams.DeleteStream(num)
return convertStreamError(m.incomingUniStreams.DeleteStream(num), protocol.StreamTypeUni, m.perspective.Opposite())
case protocol.StreamTypeBidi:
if id.InitiatedBy() == m.perspective {
return m.outgoingBidiStreams.DeleteStream(num)
return convertStreamError(m.outgoingBidiStreams.DeleteStream(num), protocol.StreamTypeBidi, m.perspective)
}
return m.incomingBidiStreams.DeleteStream(num)
return convertStreamError(m.incomingBidiStreams.DeleteStream(num), protocol.StreamTypeBidi, m.perspective.Opposite())
}
panic("")
}

View File

@@ -139,7 +139,7 @@ func (m *incomingBidiStreamsMap) DeleteStream(num protocol.StreamNum) error {
func (m *incomingBidiStreamsMap) deleteStream(num protocol.StreamNum) error {
if _, ok := m.streams[num]; !ok {
return streamError{
message: "Tried to delete unknown stream %d",
message: "Tried to delete unknown incoming stream %d",
nums: []protocol.StreamNum{num},
}
}
@@ -149,7 +149,7 @@ func (m *incomingBidiStreamsMap) deleteStream(num protocol.StreamNum) error {
if num >= m.nextStreamToAccept {
if _, ok := m.streamsToDelete[num]; ok {
return streamError{
message: "Tried to delete stream %d multiple times",
message: "Tried to delete incoming stream %d multiple times",
nums: []protocol.StreamNum{num},
}
}

View File

@@ -137,7 +137,7 @@ func (m *incomingItemsMap) DeleteStream(num protocol.StreamNum) error {
func (m *incomingItemsMap) deleteStream(num protocol.StreamNum) error {
if _, ok := m.streams[num]; !ok {
return streamError{
message: "Tried to delete unknown stream %d",
message: "Tried to delete unknown incoming stream %d",
nums: []protocol.StreamNum{num},
}
}
@@ -147,7 +147,7 @@ func (m *incomingItemsMap) deleteStream(num protocol.StreamNum) error {
if num >= m.nextStreamToAccept {
if _, ok := m.streamsToDelete[num]; ok {
return streamError{
message: "Tried to delete stream %d multiple times",
message: "Tried to delete incoming stream %d multiple times",
nums: []protocol.StreamNum{num},
}
}

View File

@@ -197,7 +197,7 @@ var _ = Describe("Streams Map (incoming)", func() {
It("errors when deleting a non-existing stream", func() {
err := m.DeleteStream(1337)
Expect(err).To(HaveOccurred())
Expect(err.(streamError).TestError()).To(MatchError("Tried to delete unknown stream 1337"))
Expect(err.(streamError).TestError()).To(MatchError("Tried to delete unknown incoming stream 1337"))
})
It("sends MAX_STREAMS frames when streams are deleted", func() {

View File

@@ -139,7 +139,7 @@ func (m *incomingUniStreamsMap) DeleteStream(num protocol.StreamNum) error {
func (m *incomingUniStreamsMap) deleteStream(num protocol.StreamNum) error {
if _, ok := m.streams[num]; !ok {
return streamError{
message: "Tried to delete unknown stream %d",
message: "Tried to delete unknown incoming stream %d",
nums: []protocol.StreamNum{num},
}
}
@@ -149,7 +149,7 @@ func (m *incomingUniStreamsMap) deleteStream(num protocol.StreamNum) error {
if num >= m.nextStreamToAccept {
if _, ok := m.streamsToDelete[num]; ok {
return streamError{
message: "Tried to delete stream %d multiple times",
message: "Tried to delete incoming stream %d multiple times",
nums: []protocol.StreamNum{num},
}
}

View File

@@ -155,7 +155,7 @@ func (m *outgoingBidiStreamsMap) DeleteStream(num protocol.StreamNum) error {
if _, ok := m.streams[num]; !ok {
return streamError{
message: "Tried to delete unknown stream %d",
message: "Tried to delete unknown outgoing stream %d",
nums: []protocol.StreamNum{num},
}
}

View File

@@ -153,7 +153,7 @@ func (m *outgoingItemsMap) DeleteStream(num protocol.StreamNum) error {
if _, ok := m.streams[num]; !ok {
return streamError{
message: "Tried to delete unknown stream %d",
message: "Tried to delete unknown outgoing stream %d",
nums: []protocol.StreamNum{num},
}
}

View File

@@ -74,7 +74,7 @@ var _ = Describe("Streams Map (outgoing)", func() {
It("errors when deleting a non-existing stream", func() {
err := m.DeleteStream(1337)
Expect(err).To(HaveOccurred())
Expect(err.(streamError).TestError()).To(MatchError("Tried to delete unknown stream 1337"))
Expect(err.(streamError).TestError()).To(MatchError("Tried to delete unknown outgoing stream 1337"))
})
It("errors when deleting a stream twice", func() {
@@ -83,7 +83,7 @@ var _ = Describe("Streams Map (outgoing)", func() {
Expect(m.DeleteStream(1)).To(Succeed())
err = m.DeleteStream(1)
Expect(err).To(HaveOccurred())
Expect(err.(streamError).TestError()).To(MatchError("Tried to delete unknown stream 1"))
Expect(err.(streamError).TestError()).To(MatchError("Tried to delete unknown outgoing stream 1"))
})
It("closes all streams when CloseWithError is called", func() {

View File

@@ -155,7 +155,7 @@ func (m *outgoingUniStreamsMap) DeleteStream(num protocol.StreamNum) error {
if _, ok := m.streams[num]; !ok {
return streamError{
message: "Tried to delete unknown stream %d",
message: "Tried to delete unknown outgoing stream %d",
nums: []protocol.StreamNum{num},
}
}

View File

@@ -209,6 +209,26 @@ var _ = Describe("Streams Map", func() {
Expect(str).ToNot(BeNil())
Expect(str.StreamID()).To(Equal(id))
})
It("errors when deleting unknown incoming unidirectional streams", func() {
id := ids.firstIncomingUniStream + 4
Expect(m.DeleteStream(id)).To(MatchError(fmt.Sprintf("Tried to delete unknown incoming stream %d", id)))
})
It("errors when deleting unknown outgoing unidirectional streams", func() {
id := ids.firstOutgoingUniStream + 4
Expect(m.DeleteStream(id)).To(MatchError(fmt.Sprintf("Tried to delete unknown outgoing stream %d", id)))
})
It("errors when deleting unknown incoming bidirectional streams", func() {
id := ids.firstIncomingBidiStream + 4
Expect(m.DeleteStream(id)).To(MatchError(fmt.Sprintf("Tried to delete unknown incoming stream %d", id)))
})
It("errors when deleting unknown outgoing bidirectional streams", func() {
id := ids.firstOutgoingBidiStream + 4
Expect(m.DeleteStream(id)).To(MatchError(fmt.Sprintf("Tried to delete unknown outgoing stream %d", id)))
})
})
Context("getting streams", func() {