more explicit tests for counting the number of streams in StreamsMap

This commit is contained in:
Marten Seemann 2016-08-05 20:33:35 +07:00
parent bf04a430ba
commit 1f25ff5569
2 changed files with 19 additions and 6 deletions

View file

@ -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()

View file

@ -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() {