fix flaky stream cancelation integration test

This commit is contained in:
Marten Seemann 2021-01-20 12:38:41 +08:00
parent 53b1cbb501
commit 8e7a4fe13f

View file

@ -347,10 +347,11 @@ var _ = Describe("Stream Cancelations", func() {
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
defer GinkgoRecover() defer GinkgoRecover()
var wg sync.WaitGroup defer close(done)
wg.Add(numStreams)
sess, err := server.Accept(context.Background()) sess, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
var wg sync.WaitGroup
wg.Add(numStreams)
for i := 0; i < numStreams; i++ { for i := 0; i < numStreams; i++ {
go func() { go func() {
defer GinkgoRecover() defer GinkgoRecover()
@ -375,7 +376,6 @@ var _ = Describe("Stream Cancelations", func() {
}() }()
} }
wg.Wait() wg.Wait()
close(done)
}() }()
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
@ -419,13 +419,13 @@ var _ = Describe("Stream Cancelations", func() {
}() }()
} }
wg.Wait() wg.Wait()
Eventually(done).Should(BeClosed())
count := atomic.LoadInt32(&counter) count := atomic.LoadInt32(&counter)
Expect(count).To(BeNumerically(">", numStreams/15)) Expect(count).To(BeNumerically(">", numStreams/15))
fmt.Fprintf(GinkgoWriter, "Successfully read from %d of %d streams.\n", count, numStreams) fmt.Fprintf(GinkgoWriter, "Successfully read from %d of %d streams.\n", count, numStreams)
Expect(sess.CloseWithError(0, "")).To(Succeed()) Expect(sess.CloseWithError(0, "")).To(Succeed())
Eventually(done).Should(BeClosed())
Expect(server.Close()).To(Succeed()) Expect(server.Close()).To(Succeed())
}) })
}) })