make sure that all packets in the send queue are sent before closing

This commit is contained in:
Marten Seemann 2020-02-13 15:22:15 +07:00
parent dd035c2f12
commit 93e724434b
2 changed files with 50 additions and 14 deletions

View file

@ -70,4 +70,30 @@ var _ = Describe("Send Queue", func() {
q.Close()
Eventually(done).Should(BeClosed())
})
It("blocks Close() until the packet has been sent out", func() {
written := make(chan []byte)
c.EXPECT().Write(gomock.Any()).Do(func(p []byte) { written <- p })
done := make(chan struct{})
go func() {
defer GinkgoRecover()
q.Run()
close(done)
}()
q.Send(getPacket([]byte("foobar")))
closed := make(chan struct{})
go func() {
defer GinkgoRecover()
q.Close()
close(closed)
}()
Consistently(closed).ShouldNot(BeClosed())
// now write the packet
Expect(written).To(Receive())
Eventually(done).Should(BeClosed())
Eventually(closed).Should(BeClosed())
})
})