diff --git a/streams_map.go b/streams_map.go index 1027aac02..16e865e2c 100644 --- a/streams_map.go +++ b/streams_map.go @@ -19,7 +19,7 @@ type streamsMap struct { streams map[protocol.StreamID]*stream // needed for round-robin scheduling openStreams []protocol.StreamID - roundRobinIndex uint32 + roundRobinIndex int nextStream protocol.StreamID // StreamID of the next Stream that will be returned by OpenStream() highestStreamOpenedByPeer protocol.StreamID @@ -255,7 +255,7 @@ func (m *streamsMap) DeleteClosedStreams() error { } if id != 0 { j++ - } else if uint32(j) < m.roundRobinIndex { + } else if j < m.roundRobinIndex { m.roundRobinIndex-- } } @@ -271,7 +271,7 @@ func (m *streamsMap) RoundRobinIterate(fn streamLambda) error { m.mutex.Lock() defer m.mutex.Unlock() - numStreams := uint32(len(m.streams)) + numStreams := len(m.streams) startIndex := m.roundRobinIndex for _, i := range []protocol.StreamID{1, 3} { @@ -284,7 +284,7 @@ func (m *streamsMap) RoundRobinIterate(fn streamLambda) error { } } - for i := uint32(0); i < numStreams; i++ { + for i := 0; i < numStreams; i++ { streamID := m.openStreams[(i+startIndex)%numStreams] if streamID == 1 || streamID == 3 { continue diff --git a/streams_map_test.go b/streams_map_test.go index fd1e6845e..23965fa11 100644 --- a/streams_map_test.go +++ b/streams_map_test.go @@ -573,7 +573,7 @@ var _ = Describe("Streams Map", func() { Expect(err).ToNot(HaveOccurred()) Expect(numIterations).To(Equal(5)) Expect(lambdaCalledForStream).To(Equal([]protocol.StreamID{7, 8, 4, 5, 6})) - Expect(m.roundRobinIndex).To(Equal(uint32(3))) + Expect(m.roundRobinIndex).To(BeEquivalentTo(3)) }) It("picks up at the index+1 where it last stopped", func() { @@ -589,7 +589,7 @@ var _ = Describe("Streams Map", func() { Expect(err).ToNot(HaveOccurred()) Expect(numIterations).To(Equal(2)) Expect(lambdaCalledForStream).To(Equal([]protocol.StreamID{4, 5})) - Expect(m.roundRobinIndex).To(Equal(uint32(2))) + Expect(m.roundRobinIndex).To(BeEquivalentTo(2)) numIterations = 0 lambdaCalledForStream = lambdaCalledForStream[:0] fn2 := func(str *stream) (bool, error) { @@ -615,7 +615,7 @@ var _ = Describe("Streams Map", func() { It("adjusts when deleting an element in front", func() { m.roundRobinIndex = 3 // stream 7 deleteStream(5) - Expect(m.roundRobinIndex).To(Equal(uint32(2))) + Expect(m.roundRobinIndex).To(BeEquivalentTo(2)) }) It("doesn't adjust when deleting an element at the back", func() { @@ -627,7 +627,7 @@ var _ = Describe("Streams Map", func() { It("doesn't adjust when deleting the element it is pointing to", func() { m.roundRobinIndex = 3 // stream 7 deleteStream(7) - Expect(m.roundRobinIndex).To(Equal(uint32(3))) + Expect(m.roundRobinIndex).To(BeEquivalentTo(3)) }) It("adjusts when deleting multiple elements", func() {