Re: [go-nuts] Virtual time for testing

2021-01-29 Thread Jesper Louis Andersen
On Thu, Jan 28, 2021 at 10:15 PM Christian Worm Mortensen wrote: > 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.Sleep(time.Second) > } > }() > return ret > } > > What is a good way

[go-nuts] Virtual time for testing

2021-01-28 Thread Christian Worm Mortensen
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.Sleep(time.Second) } }() return ret } What is a good way to do that? One way is to do it is like this: func testGenerator() { start := time.Now(