uquic/integrationtests/self/key_update_test.go

57 lines
1.3 KiB
Go

package self_test
import (
"context"
"fmt"
"io/ioutil"
"net"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/internal/handshake"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Key Update tests", func() {
var server quic.Listener
runServer := func() {
var err error
// start the server
server, err = quic.ListenAddr("localhost:0", getTLSConfig(), nil)
Expect(err).ToNot(HaveOccurred())
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
defer str.Close()
_, err = str.Write(PRDataLong)
Expect(err).ToNot(HaveOccurred())
}()
}
BeforeEach(func() {
// update keys as frequently as possible
handshake.KeyUpdateInterval = 1
runServer()
})
It("downloads a large file", func() {
sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
nil,
)
Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "")
str, err := sess.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(PRDataLong))
})
})