forked from quic-go/quic-go
more explicit tests for counting the number of streams in StreamsMap
This commit is contained in:
@@ -69,6 +69,7 @@ func (m *streamsMap) RemoveStream(id protocol.StreamID) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NumberOfStreams gets the number of open streams
|
||||||
func (m *streamsMap) NumberOfStreams() int {
|
func (m *streamsMap) NumberOfStreams() int {
|
||||||
m.mutex.RLock()
|
m.mutex.RLock()
|
||||||
defer m.mutex.RUnlock()
|
defer m.mutex.RUnlock()
|
||||||
|
|||||||
@@ -52,12 +52,24 @@ var _ = Describe("Streams Map", func() {
|
|||||||
Expect(err).To(MatchError("a stream with ID 5 already exists"))
|
Expect(err).To(MatchError("a stream with ID 5 already exists"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("gets the number of streams", func() {
|
Context("number of streams", func() {
|
||||||
Expect(m.NumberOfStreams()).To(Equal(0))
|
It("returns 0 in the beginning", func() {
|
||||||
m.PutStream(&stream{streamID: 5})
|
Expect(m.NumberOfStreams()).To(Equal(0))
|
||||||
Expect(m.NumberOfStreams()).To(Equal(1))
|
})
|
||||||
m.RemoveStream(5)
|
|
||||||
Expect(m.NumberOfStreams()).To(Equal(0))
|
It("increases the counter when a new stream is added", func() {
|
||||||
|
err := m.PutStream(&stream{streamID: 5})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(m.NumberOfStreams()).To(Equal(1))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("decreases the counter when removing a stream", func() {
|
||||||
|
err := m.PutStream(&stream{streamID: 5})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
err = m.RemoveStream(5)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(m.NumberOfStreams()).To(Equal(0))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("Lambda", func() {
|
Context("Lambda", func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user