forked from quic-go/quic-go
call the scheduleSending callback when stream.Close is called
The stream needs to send the STREAM frame containing the FIN bit.
This commit is contained in:
@@ -191,6 +191,7 @@ func (s *sendStream) Close() error {
|
|||||||
return fmt.Errorf("Close called for canceled stream %d", s.streamID)
|
return fmt.Errorf("Close called for canceled stream %d", s.streamID)
|
||||||
}
|
}
|
||||||
s.finishedWriting = true
|
s.finishedWriting = true
|
||||||
|
s.sender.scheduleSending()
|
||||||
s.ctxCancel()
|
s.ctxCancel()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ var _ = Describe("Send Stream", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("cancels the context when Close is called", func() {
|
It("cancels the context when Close is called", func() {
|
||||||
|
mockSender.EXPECT().scheduleSending()
|
||||||
Expect(str.Context().Done()).ToNot(BeClosed())
|
Expect(str.Context().Done()).ToNot(BeClosed())
|
||||||
str.Close()
|
str.Close()
|
||||||
Expect(str.Context().Done()).To(BeClosed())
|
Expect(str.Context().Done()).To(BeClosed())
|
||||||
@@ -174,7 +175,7 @@ var _ = Describe("Send Stream", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't queue a BLOCKED frame if the stream is flow control blocked, but the frame popped has the FIN bit set", func() {
|
It("doesn't queue a BLOCKED frame if the stream is flow control blocked, but the frame popped has the FIN bit set", func() {
|
||||||
mockSender.EXPECT().scheduleSending()
|
mockSender.EXPECT().scheduleSending().Times(2) // once for the Write, once for the Close
|
||||||
mockFC.EXPECT().SendWindowSize().Return(protocol.ByteCount(9999))
|
mockFC.EXPECT().SendWindowSize().Return(protocol.ByteCount(9999))
|
||||||
mockFC.EXPECT().AddBytesSent(protocol.ByteCount(6))
|
mockFC.EXPECT().AddBytesSent(protocol.ByteCount(6))
|
||||||
// don't EXPECT a call to mockFC.IsNewlyBlocked
|
// don't EXPECT a call to mockFC.IsNewlyBlocked
|
||||||
@@ -305,12 +306,14 @@ var _ = Describe("Send Stream", func() {
|
|||||||
|
|
||||||
Context("closing", func() {
|
Context("closing", func() {
|
||||||
It("doesn't allow writes after it has been closed", func() {
|
It("doesn't allow writes after it has been closed", func() {
|
||||||
|
mockSender.EXPECT().scheduleSending()
|
||||||
str.Close()
|
str.Close()
|
||||||
_, err := strWithTimeout.Write([]byte("foobar"))
|
_, err := strWithTimeout.Write([]byte("foobar"))
|
||||||
Expect(err).To(MatchError("write on closed stream 1337"))
|
Expect(err).To(MatchError("write on closed stream 1337"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("allows FIN", func() {
|
It("allows FIN", func() {
|
||||||
|
mockSender.EXPECT().scheduleSending()
|
||||||
str.Close()
|
str.Close()
|
||||||
f := str.popStreamFrame(1000)
|
f := str.popStreamFrame(1000)
|
||||||
Expect(f).ToNot(BeNil())
|
Expect(f).ToNot(BeNil())
|
||||||
@@ -319,12 +322,13 @@ var _ = Describe("Send Stream", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't send a FIN when there's still data", func() {
|
It("doesn't send a FIN when there's still data", func() {
|
||||||
|
mockSender.EXPECT().scheduleSending()
|
||||||
frameHeaderLen := protocol.ByteCount(4)
|
frameHeaderLen := protocol.ByteCount(4)
|
||||||
mockFC.EXPECT().SendWindowSize().Return(protocol.ByteCount(9999)).Times(2)
|
mockFC.EXPECT().SendWindowSize().Return(protocol.ByteCount(9999)).Times(2)
|
||||||
mockFC.EXPECT().AddBytesSent(gomock.Any()).Times(2)
|
mockFC.EXPECT().AddBytesSent(gomock.Any()).Times(2)
|
||||||
mockFC.EXPECT().IsNewlyBlocked()
|
mockFC.EXPECT().IsNewlyBlocked()
|
||||||
str.dataForWriting = []byte("foobar")
|
str.dataForWriting = []byte("foobar")
|
||||||
str.Close()
|
Expect(str.Close()).To(Succeed())
|
||||||
f := str.popStreamFrame(3 + frameHeaderLen)
|
f := str.popStreamFrame(3 + frameHeaderLen)
|
||||||
Expect(f).ToNot(BeNil())
|
Expect(f).ToNot(BeNil())
|
||||||
Expect(f.Data).To(Equal([]byte("foo")))
|
Expect(f.Data).To(Equal([]byte("foo")))
|
||||||
@@ -341,6 +345,7 @@ var _ = Describe("Send Stream", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't allow FIN twice", func() {
|
It("doesn't allow FIN twice", func() {
|
||||||
|
mockSender.EXPECT().scheduleSending()
|
||||||
str.Close()
|
str.Close()
|
||||||
f := str.popStreamFrame(1000)
|
f := str.popStreamFrame(1000)
|
||||||
Expect(f).ToNot(BeNil())
|
Expect(f).ToNot(BeNil())
|
||||||
@@ -449,6 +454,7 @@ var _ = Describe("Send Stream", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't cancel when the stream was already closed", func() {
|
It("doesn't cancel when the stream was already closed", func() {
|
||||||
|
mockSender.EXPECT().scheduleSending()
|
||||||
err := str.Close()
|
err := str.Close()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
err = str.CancelWrite(123)
|
err = str.CancelWrite(123)
|
||||||
@@ -511,6 +517,7 @@ var _ = Describe("Send Stream", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("is finished after Close()", func() {
|
It("is finished after Close()", func() {
|
||||||
|
mockSender.EXPECT().scheduleSending()
|
||||||
str.Close()
|
str.Close()
|
||||||
f := str.popStreamFrame(1000)
|
f := str.popStreamFrame(1000)
|
||||||
Expect(f.FinBit).To(BeTrue())
|
Expect(f.FinBit).To(BeTrue())
|
||||||
|
|||||||
Reference in New Issue
Block a user