fix race condition in the crypto setup tests

This commit is contained in:
Marten Seemann 2020-02-25 15:05:02 +07:00
parent d4757395b6
commit d277e013ab

View file

@ -263,8 +263,6 @@ var _ = Describe("Crypto Setup TLS", func() {
})
Context("doing the handshake", func() {
var testDone chan struct{}
generateCert := func() tls.Certificate {
priv, err := rsa.GenerateKey(rand.Reader, 2048)
Expect(err).ToNot(HaveOccurred())
@ -284,14 +282,6 @@ var _ = Describe("Crypto Setup TLS", func() {
}
}
BeforeEach(func() {
testDone = make(chan struct{})
})
AfterEach(func() {
close(testDone)
})
handshake := func(client CryptoSetup, cChunkChan <-chan chunk,
server CryptoSetup, sChunkChan <-chan chunk) {
done := make(chan struct{})
@ -303,7 +293,7 @@ var _ = Describe("Crypto Setup TLS", func() {
server.HandleMessage(c.data, c.encLevel)
case c := <-sChunkChan:
client.HandleMessage(c.data, c.encLevel)
case <-testDone: // handshake complete
case <-done: // handshake complete
return
}
}
@ -311,13 +301,13 @@ var _ = Describe("Crypto Setup TLS", func() {
go func() {
defer GinkgoRecover()
defer close(done)
server.RunHandshake()
ticket, err := server.GetSessionTicket()
Expect(err).ToNot(HaveOccurred())
if ticket != nil {
client.HandleMessage(ticket, protocol.Encryption1RTT)
}
close(done)
}()
client.RunHandshake()