jostyee / gomock

Automatically exported from code.google.com/p/gomock
Apache License 2.0
0 stars 0 forks source link

Request for blocking calls. #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I would like to add support for mocking a blocking call.

Example syntax could be:

mockSocket.EXPECT().Read().Block()

signalChan := make(chan bool)
mockSocket.EXPECT().Read().BlockUntil(signalChan).Return([]{0}, nil)

Original issue reported on code.google.com by awre...@gmail.com on 12 Sep 2011 at 6:48

GoogleCodeExporter commented 9 years ago
I'm not sure how this would work. After one thread blocks on this mock call and 
the test finishes, how would we kill the blocking thread and reclaim its 
resources?

Original comment by awre...@gmail.com on 14 Sep 2011 at 9:52

GoogleCodeExporter commented 9 years ago
This is already possible with the Do method.

mockSocket.EXPECT().Read().Do(func() { ... })

Replace "..." with whatever mechanism you'd prefer (e.g. a chan).

Original comment by dsymo...@golang.org on 19 Sep 2011 at 12:46