petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add timer verification

rauizab opened this issue · comments

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

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

Thank you. It is working.