fix flaky server unit test

This commit is contained in:
Marten Seemann 2019-04-03 01:27:31 +09:00
parent 907071221c
commit 7b569ba071

View file

@ -507,7 +507,8 @@ var _ = Describe("Server", func() {
It("never blocks when calling the onHandshakeComplete callback", func() { It("never blocks when calling the onHandshakeComplete callback", func() {
const num = 50 const num = 50
done := make(chan struct{}, num) runs := make(chan struct{}, num)
contexts := make(chan struct{}, num)
serv.newSession = func( serv.newSession = func(
_ connection, _ connection,
runner sessionRunner, runner sessionRunner,
@ -521,10 +522,9 @@ var _ = Describe("Server", func() {
_ protocol.VersionNumber, _ protocol.VersionNumber,
) (quicSession, error) { ) (quicSession, error) {
sess := NewMockQuicSession(mockCtrl) sess := NewMockQuicSession(mockCtrl)
sess.EXPECT().run().Do(func() {}) sess.EXPECT().run().Do(func() { runs <- struct{}{} })
sess.EXPECT().Context().Return(context.Background()) sess.EXPECT().Context().Do(func() { contexts <- struct{}{} }).Return(context.Background())
runner.OnHandshakeComplete(sess) runner.OnHandshakeComplete(sess)
done <- struct{}{}
return sess, nil return sess, nil
} }
@ -534,7 +534,8 @@ var _ = Describe("Server", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
} }
}() }()
Eventually(done).Should(HaveLen(num)) Eventually(runs).Should(HaveLen(num))
Eventually(contexts).Should(HaveLen(num))
}) })
}) })
}) })