mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
rename the EarlySession to EarlyConnection
This commit is contained in:
parent
fda9f72161
commit
6aaa9a817c
17 changed files with 232 additions and 228 deletions
|
@ -107,7 +107,7 @@ var _ = Describe("Server", func() {
|
|||
var (
|
||||
qpackDecoder *qpack.Decoder
|
||||
str *mockquic.MockStream
|
||||
sess *mockquic.MockEarlySession
|
||||
conn *mockquic.MockEarlyConnection
|
||||
exampleGetRequest *http.Request
|
||||
examplePostRequest *http.Request
|
||||
)
|
||||
|
@ -164,10 +164,10 @@ var _ = Describe("Server", func() {
|
|||
qpackDecoder = qpack.NewDecoder(nil)
|
||||
str = mockquic.NewMockStream(mockCtrl)
|
||||
|
||||
sess = mockquic.NewMockEarlySession(mockCtrl)
|
||||
conn = mockquic.NewMockEarlyConnection(mockCtrl)
|
||||
addr := &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 1337}
|
||||
sess.EXPECT().RemoteAddr().Return(addr).AnyTimes()
|
||||
sess.EXPECT().LocalAddr().AnyTimes()
|
||||
conn.EXPECT().RemoteAddr().Return(addr).AnyTimes()
|
||||
conn.EXPECT().LocalAddr().AnyTimes()
|
||||
})
|
||||
|
||||
It("calls the HTTP handler function", func() {
|
||||
|
@ -183,7 +183,7 @@ var _ = Describe("Server", func() {
|
|||
}).AnyTimes()
|
||||
str.EXPECT().CancelRead(gomock.Any())
|
||||
|
||||
Expect(s.handleRequest(sess, str, qpackDecoder, nil)).To(Equal(requestError{}))
|
||||
Expect(s.handleRequest(conn, str, qpackDecoder, nil)).To(Equal(requestError{}))
|
||||
var req *http.Request
|
||||
Eventually(requestChan).Should(Receive(&req))
|
||||
Expect(req.Host).To(Equal("www.example.com"))
|
||||
|
@ -200,7 +200,7 @@ var _ = Describe("Server", func() {
|
|||
str.EXPECT().Write(gomock.Any()).DoAndReturn(responseBuf.Write).AnyTimes()
|
||||
str.EXPECT().CancelRead(gomock.Any())
|
||||
|
||||
serr := s.handleRequest(sess, str, qpackDecoder, nil)
|
||||
serr := s.handleRequest(conn, str, qpackDecoder, nil)
|
||||
Expect(serr.err).ToNot(HaveOccurred())
|
||||
hfs := decodeHeader(responseBuf)
|
||||
Expect(hfs).To(HaveKeyWithValue(":status", []string{"200"}))
|
||||
|
@ -217,7 +217,7 @@ var _ = Describe("Server", func() {
|
|||
str.EXPECT().Write(gomock.Any()).DoAndReturn(responseBuf.Write).AnyTimes()
|
||||
str.EXPECT().CancelRead(gomock.Any())
|
||||
|
||||
serr := s.handleRequest(sess, str, qpackDecoder, nil)
|
||||
serr := s.handleRequest(conn, str, qpackDecoder, nil)
|
||||
Expect(serr.err).ToNot(HaveOccurred())
|
||||
hfs := decodeHeader(responseBuf)
|
||||
Expect(hfs).To(HaveKeyWithValue(":status", []string{"500"}))
|
||||
|
@ -234,22 +234,22 @@ var _ = Describe("Server", func() {
|
|||
str.EXPECT().Write([]byte("foobar"))
|
||||
// don't EXPECT CancelRead()
|
||||
|
||||
serr := s.handleRequest(sess, str, qpackDecoder, nil)
|
||||
serr := s.handleRequest(conn, str, qpackDecoder, nil)
|
||||
Expect(serr.err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
Context("control stream handling", func() {
|
||||
var sess *mockquic.MockEarlySession
|
||||
var conn *mockquic.MockEarlyConnection
|
||||
testDone := make(chan struct{})
|
||||
|
||||
BeforeEach(func() {
|
||||
sess = mockquic.NewMockEarlySession(mockCtrl)
|
||||
conn = mockquic.NewMockEarlyConnection(mockCtrl)
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Write(gomock.Any())
|
||||
sess.EXPECT().OpenUniStream().Return(controlStr, nil)
|
||||
sess.EXPECT().AcceptStream(gomock.Any()).Return(nil, errors.New("done"))
|
||||
sess.EXPECT().RemoteAddr().Return(&net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 1337}).AnyTimes()
|
||||
sess.EXPECT().LocalAddr().AnyTimes()
|
||||
conn.EXPECT().OpenUniStream().Return(controlStr, nil)
|
||||
conn.EXPECT().AcceptStream(gomock.Any()).Return(nil, errors.New("done"))
|
||||
conn.EXPECT().RemoteAddr().Return(&net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 1337}).AnyTimes()
|
||||
conn.EXPECT().LocalAddr().AnyTimes()
|
||||
})
|
||||
|
||||
AfterEach(func() { testDone <- struct{}{} })
|
||||
|
@ -260,15 +260,15 @@ var _ = Describe("Server", func() {
|
|||
(&settingsFrame{}).Write(buf)
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return controlStr, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
s.handleConn(sess)
|
||||
time.Sleep(scaleDuration(20 * time.Millisecond)) // don't EXPECT any calls to sess.CloseWithError
|
||||
s.handleConn(conn)
|
||||
time.Sleep(scaleDuration(20 * time.Millisecond)) // don't EXPECT any calls to conn.CloseWithError
|
||||
})
|
||||
|
||||
for _, t := range []uint64{streamTypeQPACKEncoderStream, streamTypeQPACKDecoderStream} {
|
||||
|
@ -284,14 +284,14 @@ var _ = Describe("Server", func() {
|
|||
str := mockquic.NewMockStream(mockCtrl)
|
||||
str.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return str, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
s.handleConn(sess)
|
||||
s.handleConn(conn)
|
||||
time.Sleep(scaleDuration(20 * time.Millisecond)) // don't EXPECT any calls to str.CancelRead
|
||||
})
|
||||
}
|
||||
|
@ -306,14 +306,14 @@ var _ = Describe("Server", func() {
|
|||
close(done)
|
||||
})
|
||||
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return str, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
s.handleConn(sess)
|
||||
s.handleConn(conn)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
|
@ -323,20 +323,20 @@ var _ = Describe("Server", func() {
|
|||
(&dataFrame{}).Write(buf)
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return controlStr, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
done := make(chan struct{})
|
||||
sess.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
conn.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
defer GinkgoRecover()
|
||||
Expect(code).To(BeEquivalentTo(errorMissingSettings))
|
||||
close(done)
|
||||
})
|
||||
s.handleConn(sess)
|
||||
s.handleConn(conn)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
|
@ -348,20 +348,20 @@ var _ = Describe("Server", func() {
|
|||
buf.Write(b.Bytes()[:b.Len()-1])
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return controlStr, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
done := make(chan struct{})
|
||||
sess.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
conn.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
defer GinkgoRecover()
|
||||
Expect(code).To(BeEquivalentTo(errorFrameError))
|
||||
close(done)
|
||||
})
|
||||
s.handleConn(sess)
|
||||
s.handleConn(conn)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
|
@ -371,20 +371,20 @@ var _ = Describe("Server", func() {
|
|||
(&dataFrame{}).Write(buf)
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return controlStr, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
done := make(chan struct{})
|
||||
sess.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
conn.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
defer GinkgoRecover()
|
||||
Expect(code).To(BeEquivalentTo(errorStreamCreationError))
|
||||
close(done)
|
||||
})
|
||||
s.handleConn(sess)
|
||||
s.handleConn(conn)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
|
@ -395,45 +395,45 @@ var _ = Describe("Server", func() {
|
|||
(&settingsFrame{Datagram: true}).Write(buf)
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Read(gomock.Any()).DoAndReturn(buf.Read).AnyTimes()
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
return controlStr, nil
|
||||
})
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
sess.EXPECT().ConnectionState().Return(quic.ConnectionState{SupportsDatagrams: false})
|
||||
conn.EXPECT().ConnectionState().Return(quic.ConnectionState{SupportsDatagrams: false})
|
||||
done := make(chan struct{})
|
||||
sess.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, reason string) {
|
||||
conn.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, reason string) {
|
||||
defer GinkgoRecover()
|
||||
Expect(code).To(BeEquivalentTo(errorSettingsError))
|
||||
Expect(reason).To(Equal("missing QUIC Datagram support"))
|
||||
close(done)
|
||||
})
|
||||
s.handleConn(sess)
|
||||
s.handleConn(conn)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
})
|
||||
|
||||
Context("stream- and connection-level errors", func() {
|
||||
var sess *mockquic.MockEarlySession
|
||||
var conn *mockquic.MockEarlyConnection
|
||||
testDone := make(chan struct{})
|
||||
|
||||
BeforeEach(func() {
|
||||
testDone = make(chan struct{})
|
||||
addr := &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 1337}
|
||||
sess = mockquic.NewMockEarlySession(mockCtrl)
|
||||
conn = mockquic.NewMockEarlyConnection(mockCtrl)
|
||||
controlStr := mockquic.NewMockStream(mockCtrl)
|
||||
controlStr.EXPECT().Write(gomock.Any())
|
||||
sess.EXPECT().OpenUniStream().Return(controlStr, nil)
|
||||
sess.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
conn.EXPECT().OpenUniStream().Return(controlStr, nil)
|
||||
conn.EXPECT().AcceptUniStream(gomock.Any()).DoAndReturn(func(context.Context) (quic.ReceiveStream, error) {
|
||||
<-testDone
|
||||
return nil, errors.New("test done")
|
||||
})
|
||||
sess.EXPECT().AcceptStream(gomock.Any()).Return(str, nil)
|
||||
sess.EXPECT().AcceptStream(gomock.Any()).Return(nil, errors.New("done"))
|
||||
sess.EXPECT().RemoteAddr().Return(addr).AnyTimes()
|
||||
sess.EXPECT().LocalAddr().AnyTimes()
|
||||
conn.EXPECT().AcceptStream(gomock.Any()).Return(str, nil)
|
||||
conn.EXPECT().AcceptStream(gomock.Any()).Return(nil, errors.New("done"))
|
||||
conn.EXPECT().RemoteAddr().Return(addr).AnyTimes()
|
||||
conn.EXPECT().LocalAddr().AnyTimes()
|
||||
})
|
||||
|
||||
AfterEach(func() { testDone <- struct{}{} })
|
||||
|
@ -456,7 +456,7 @@ var _ = Describe("Server", func() {
|
|||
str.EXPECT().CancelRead(quic.StreamErrorCode(errorNoError))
|
||||
str.EXPECT().Close().Do(func() { close(done) })
|
||||
|
||||
s.handleConn(sess)
|
||||
s.handleConn(conn)
|
||||
Eventually(done).Should(BeClosed())
|
||||
hfs := decodeHeader(responseBuf)
|
||||
Expect(hfs).To(HaveKeyWithValue(":status", []string{"200"}))
|
||||
|
@ -478,7 +478,7 @@ var _ = Describe("Server", func() {
|
|||
str.EXPECT().Write(gomock.Any()).DoAndReturn(responseBuf.Write).AnyTimes()
|
||||
str.EXPECT().CancelWrite(quic.StreamErrorCode(errorFrameError)).Do(func(quic.StreamErrorCode) { close(done) })
|
||||
|
||||
s.handleConn(sess)
|
||||
s.handleConn(conn)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
|
@ -493,7 +493,7 @@ var _ = Describe("Server", func() {
|
|||
str.EXPECT().Read(gomock.Any()).Return(0, testErr)
|
||||
str.EXPECT().CancelWrite(quic.StreamErrorCode(errorRequestIncomplete)).Do(func(quic.StreamErrorCode) { close(done) })
|
||||
|
||||
s.handleConn(sess)
|
||||
s.handleConn(conn)
|
||||
Consistently(handlerCalled).ShouldNot(BeClosed())
|
||||
})
|
||||
|
||||
|
@ -511,11 +511,11 @@ var _ = Describe("Server", func() {
|
|||
}).AnyTimes()
|
||||
|
||||
done := make(chan struct{})
|
||||
sess.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
conn.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(code quic.ApplicationErrorCode, _ string) {
|
||||
Expect(code).To(Equal(quic.ApplicationErrorCode(errorFrameUnexpected)))
|
||||
close(done)
|
||||
})
|
||||
s.handleConn(sess)
|
||||
s.handleConn(conn)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
|
@ -538,7 +538,7 @@ var _ = Describe("Server", func() {
|
|||
done := make(chan struct{})
|
||||
str.EXPECT().CancelWrite(quic.StreamErrorCode(errorFrameError)).Do(func(quic.StreamErrorCode) { close(done) })
|
||||
|
||||
s.handleConn(sess)
|
||||
s.handleConn(conn)
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
})
|
||||
|
@ -560,7 +560,7 @@ var _ = Describe("Server", func() {
|
|||
}).AnyTimes()
|
||||
str.EXPECT().CancelRead(quic.StreamErrorCode(errorNoError))
|
||||
|
||||
serr := s.handleRequest(sess, str, qpackDecoder, nil)
|
||||
serr := s.handleRequest(conn, str, qpackDecoder, nil)
|
||||
Expect(serr.err).ToNot(HaveOccurred())
|
||||
Eventually(handlerCalled).Should(BeClosed())
|
||||
})
|
||||
|
@ -583,7 +583,7 @@ var _ = Describe("Server", func() {
|
|||
}).AnyTimes()
|
||||
str.EXPECT().CancelRead(quic.StreamErrorCode(errorNoError))
|
||||
|
||||
serr := s.handleRequest(sess, str, qpackDecoder, nil)
|
||||
serr := s.handleRequest(conn, str, qpackDecoder, nil)
|
||||
Expect(serr.err).ToNot(HaveOccurred())
|
||||
Eventually(handlerCalled).Should(BeClosed())
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue