add OpenStreamSync() method to Session interface

This commit is contained in:
Marten Seemann
2017-02-20 15:49:32 +07:00
parent 9c46ee6b24
commit 592ef45fdf
5 changed files with 18 additions and 2 deletions

View File

@@ -38,6 +38,9 @@ func (s *mockSession) AcceptStream() (utils.Stream, error) {
func (s *mockSession) OpenStream() (utils.Stream, error) {
panic("not implemented")
}
func (s *mockSession) OpenStreamSync() (utils.Stream, error) {
panic("not implemented")
}
func (s *mockSession) Close(e error) error {
s.closed = true
s.closedWithError = e

View File

@@ -15,9 +15,8 @@ type Session interface {
// guaranteed to return the smallest unopened stream
// special error for "too many streams, retry later"
OpenStream() (utils.Stream, error)
// TODO: implement this
// blocks until a new stream can be opened, if the maximum number of stream is opened
// OpenStreamSync() (utils.Stream, error)
OpenStreamSync() (utils.Stream, error)
RemoteAddr() net.Addr
Close(error) error
}

View File

@@ -38,6 +38,9 @@ func (s *mockSession) AcceptStream() (utils.Stream, error) {
func (s *mockSession) OpenStream() (utils.Stream, error) {
return &stream{streamID: 1337}, nil
}
func (s *mockSession) OpenStreamSync() (utils.Stream, error) {
panic("not implemented")
}
func (s *mockSession) RemoteAddr() net.Addr {
panic("not implemented")
}

View File

@@ -681,6 +681,10 @@ func (s *session) OpenStream() (utils.Stream, error) {
return s.streamsMap.OpenStream()
}
func (s *session) OpenStreamSync() (utils.Stream, error) {
return s.streamsMap.OpenStreamSync()
}
func (s *session) queueResetStreamFrame(id protocol.StreamID, offset protocol.ByteCount) {
s.packer.QueueControlFrameForNextPacket(&frames.RstStreamFrame{
StreamID: id,

View File

@@ -1240,6 +1240,13 @@ var _ = Describe("Session", func() {
_, ok := str.(utils.Stream)
Expect(ok).To(BeFalse())
})
// all relevant tests for this are in the streamsMap
It("opens streams synchronously", func() {
str, err := sess.OpenStreamSync()
Expect(err).ToNot(HaveOccurred())
Expect(str).ToNot(BeNil())
})
})
Context("counting streams", func() {