properly stop the testserver at the end of a test in integration tests

This commit is contained in:
Marten Seemann
2017-12-20 17:33:36 +07:00
parent ed212b789c
commit e4e74e0873

View File

@@ -25,8 +25,9 @@ var (
PRData = GeneratePRData(dataLen) PRData = GeneratePRData(dataLen)
PRDataLong = GeneratePRData(dataLenLong) PRDataLong = GeneratePRData(dataLenLong)
server *h2quic.Server server *h2quic.Server
port string stoppedServing chan struct{}
port string
) )
func init() { func init() {
@@ -95,14 +96,18 @@ func StartQuicServer(versions []protocol.VersionNumber) {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
port = strconv.Itoa(conn.LocalAddr().(*net.UDPAddr).Port) port = strconv.Itoa(conn.LocalAddr().(*net.UDPAddr).Port)
stoppedServing = make(chan struct{})
go func() { go func() {
defer GinkgoRecover() defer GinkgoRecover()
server.Serve(conn) server.Serve(conn)
close(stoppedServing)
}() }()
} }
func StopQuicServer() { func StopQuicServer() {
Expect(server.Close()).NotTo(HaveOccurred()) Expect(server.Close()).NotTo(HaveOccurred())
Eventually(stoppedServing).Should(BeClosed())
} }
func Port() string { func Port() string {