Re: [go-nuts] Re: Virtual time for testing

2021-02-02 Thread Christian Worm Mortensen
Hi Roger, Thank you for sharing how you have solved the problem in the past and the problems you have had. As I see it, my proposal would solve your problem perfectly in many cases without the need to keep track of anything. If you like it, it may be helpful to express your support: https://github

Re: [go-nuts] Re: Virtual time for testing

2021-02-01 Thread roger peppe
On Sat, 30 Jan 2021 at 20:12, Christian Worm Mortensen wrote: > Hi Mike, > > Thank you for your consideration. I think you exactly got the essence of > my question: How do I wait on all go routines to finish (or be blocked on > one or more channels) before advancing time. > This is an interestin

Re: [go-nuts] Re: Virtual time for testing

2021-01-31 Thread Christian Worm Mortensen
I ended up creating an issue on this: https://github.com/golang/go/issues/44026 On Sat, Jan 30, 2021 at 9:12 PM Christian Worm Mortensen wrote: > Hi Mike, > > Thank you for your consideration. I think you exactly got the essence of > my question: How do I wait on all go routines to finish (or

Re: [go-nuts] Re: Virtual time for testing

2021-01-30 Thread Christian Worm Mortensen
Hi Mike, Thank you for your consideration. I think you exactly got the essence of my question: How do I wait on all go routines to finish (or be blocked on one or more channels) before advancing time. A key thing I would like from such a solution is that it does not require too heavy modification

[go-nuts] Re: Virtual time for testing

2021-01-29 Thread mspr...@us.ibm.com
Volker: injecting sleep is a nice idea, in the general vein that Jesper said of injecting time. However, as soon as we zoom out a step and need to test both that generator and the goroutine(s) consuming and acting upon that channel activity, we get back to the essence of the original question:

[go-nuts] Re: Virtual time for testing

2021-01-29 Thread Volker Dobler
One way to do this is have an internal implementation like func generatorImpl(sleep func(time.Duration)) <-chan int and func generator just calls that one with time.Sleep. Tests are done against generatorImpl where you know have detailed control of how much (typically none) time is actually slept.

Re: [go-nuts] Re: Virtual time for testing

2021-01-28 Thread Christian Worm Mortensen
Hi Amnon, Thank you for your suggestion. I have taken a look at the package but it does not seem to really work. It seems to rely on runtime.Gosched() to suspend the current go routine until all other go routines are blocked. That is, it relies on runtime.Gosched() to provide functionality simila

[go-nuts] Re: Virtual time for testing

2021-01-28 Thread Amnon
Try something like github.com/facebookgo/clock On Thursday, 28 January 2021 at 21:15:50 UTC Christian Worm Mortensen wrote: > Hi! > > Suppose I want to unit test this function: > > func generator() <-chan int { > ret := make(chan int) > go func() { > for i := 0; i < 10; i++ { > ret <- i > time.