mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
implement handling of MAX_STREAM_ID frames
This commit is contained in:
parent
cd4bcda458
commit
46e20ce8c9
11 changed files with 350 additions and 53 deletions
|
@ -23,56 +23,107 @@ var _ = Describe("Streams Map (outgoing)", func() {
|
|||
m = newOutgoingItemsMap(firstNewStream, newItem)
|
||||
})
|
||||
|
||||
It("opens streams", func() {
|
||||
str, err := m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str).To(Equal(firstNewStream))
|
||||
str, err = m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str).To(Equal(firstNewStream + 4))
|
||||
Context("no stream ID limit", func() {
|
||||
BeforeEach(func() {
|
||||
m.SetMaxStream(0xffffffff)
|
||||
})
|
||||
|
||||
It("opens streams", func() {
|
||||
str, err := m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str).To(Equal(firstNewStream))
|
||||
str, err = m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str).To(Equal(firstNewStream + 4))
|
||||
})
|
||||
|
||||
It("doesn't open streams after it has been closed", func() {
|
||||
testErr := errors.New("close")
|
||||
m.CloseWithError(testErr)
|
||||
_, err := m.OpenStream()
|
||||
Expect(err).To(MatchError(testErr))
|
||||
})
|
||||
|
||||
It("gets streams", func() {
|
||||
_, err := m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str, err := m.GetStream(firstNewStream)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str).To(Equal(firstNewStream))
|
||||
})
|
||||
|
||||
It("errors when trying to get a stream that has not yet been opened", func() {
|
||||
_, err := m.GetStream(10)
|
||||
Expect(err).To(MatchError(qerr.Error(qerr.InvalidStreamID, "peer attempted to open stream 10")))
|
||||
})
|
||||
|
||||
It("deletes streams", func() {
|
||||
_, err := m.OpenStream() // opens stream 10
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = m.DeleteStream(10)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str, err := m.GetStream(10)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str).To(BeNil())
|
||||
})
|
||||
|
||||
It("errors when deleting a non-existing stream", func() {
|
||||
err := m.DeleteStream(1337)
|
||||
Expect(err).To(MatchError("Tried to delete unknown stream 1337"))
|
||||
})
|
||||
|
||||
It("errors when deleting a stream twice", func() {
|
||||
_, err := m.OpenStream() // opens stream 10
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = m.DeleteStream(10)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = m.DeleteStream(10)
|
||||
Expect(err).To(MatchError("Tried to delete unknown stream 10"))
|
||||
})
|
||||
})
|
||||
|
||||
It("doesn't open streams after it has been closed", func() {
|
||||
testErr := errors.New("close")
|
||||
m.CloseWithError(testErr)
|
||||
_, err := m.OpenStream()
|
||||
Expect(err).To(MatchError(testErr))
|
||||
})
|
||||
Context("with stream ID limits", func() {
|
||||
It("errors when no stream can be opened immediately", func() {
|
||||
_, err := m.OpenStream()
|
||||
Expect(err).To(MatchError(qerr.TooManyOpenStreams))
|
||||
})
|
||||
|
||||
It("gets streams", func() {
|
||||
_, err := m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str, err := m.GetStream(firstNewStream)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str).To(Equal(firstNewStream))
|
||||
})
|
||||
It("blocks until a stream can be opened synchronously", func() {
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
str, err := m.OpenStreamSync()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str).To(Equal(firstNewStream))
|
||||
close(done)
|
||||
}()
|
||||
|
||||
It("errors when trying to get a stream that has not yet been opened", func() {
|
||||
_, err := m.GetStream(10)
|
||||
Expect(err).To(MatchError(qerr.Error(qerr.InvalidStreamID, "peer attempted to open stream 10")))
|
||||
})
|
||||
Consistently(done).ShouldNot(BeClosed())
|
||||
m.SetMaxStream(firstNewStream)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
It("deletes streams", func() {
|
||||
_, err := m.OpenStream() // opens stream 10
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = m.DeleteStream(10)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
str, err := m.GetStream(10)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str).To(BeNil())
|
||||
})
|
||||
It("stops opening synchronously when it is closed", func() {
|
||||
testErr := errors.New("test error")
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
_, err := m.OpenStreamSync()
|
||||
Expect(err).To(MatchError(testErr))
|
||||
close(done)
|
||||
}()
|
||||
|
||||
It("errors when deleting a non-existing stream", func() {
|
||||
err := m.DeleteStream(1337)
|
||||
Expect(err).To(MatchError("Tried to delete unknown stream 1337"))
|
||||
})
|
||||
Consistently(done).ShouldNot(BeClosed())
|
||||
m.CloseWithError(testErr)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
It("errors when deleting a stream twice", func() {
|
||||
_, err := m.OpenStream() // opens stream 10
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = m.DeleteStream(10)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = m.DeleteStream(10)
|
||||
Expect(err).To(MatchError("Tried to delete unknown stream 10"))
|
||||
It("doesn't reduce the stream limit", func() {
|
||||
m.SetMaxStream(firstNewStream)
|
||||
m.SetMaxStream(firstNewStream - 4)
|
||||
str, err := m.OpenStream()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(str).To(Equal(firstNewStream))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue