Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

After() should block _after_ the mocked method is called #464

Closed
skonefal opened this issue Jun 13, 2017 · 2 comments
Closed

After() should block _after_ the mocked method is called #464

skonefal opened this issue Jun 13, 2017 · 2 comments

Comments

@skonefal
Copy link

Currently the timer in After(duration) method is started immediately when mock is defined. This is a problem when user would like to test two mocked methods that are run one after another.

For example in following snippet:

func doWaiting(w1 Waiter, w2 Waiter) {
  w1.Wait()
  w2.Wait()
}

func TestWaiter() {
  w1 := make(waiterMock)
  w2 := make(waiterMock)
  w1.On("Wait").After(100 * time.Milisecond)
  w2.On("Wait").After(100 * time.Milisecond)
 
  doWaiting(w1, w2)
}

Documentation specifies, that the call will block so that expected execution time of doWaiting function is 200ms.

Unfortunately, the actual execution time is 100ms, because timer in After starts when mock is defined.

This leads to mock code that misleading:

  w1.On("Wait").After(100 * time.Milisecond)
  w2.On("Wait").After(200 * time.Milisecond)
@devdinu
Copy link
Contributor

devdinu commented Dec 29, 2017

I've raised a PR #529 comments are welcome.

@ernesto-jimenez
Copy link
Member

Fixed in #529

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants