petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
253 stars 28 forks source link

Add timer verification #63

Closed rauizab closed 6 years ago

rauizab commented 6 years ago

Hi

I am trying to tests some parallelism and the test needs some milliseconds to make the final call. Is there a way to check a mock call repeatedly , like checking every 100 milleseconds until one second has passed?

Thanks in advanced

petergtz commented 6 years ago

Hi @rauizab,

I came across this recently as well and solved it like this:

Eventually(func() []string {
    return pegomock.InterceptMockFailures(func() {
       myMock.VerifyWasCalled(Once()).SomeMethod()
    })
}).Should(BeEmpty())

This waits for 1s and checks every 10ms. See http://onsi.github.io/gomega/#eventually for more information.

This assumes you're using Gomega and Ginkgo. Without these, I wouldn't know how solve this easily.

Hope this helps, Peter

rauizab commented 6 years ago

Thank you. It is working.