A fake that answers at once rarely has two calls under way together, so a
count alone proves little. fanouttest.InFlight holds
each call until enough others have joined it. A test of a limit holds calls
until one more than the limit are under way. A fan-out that keeps its limit
never allows that, so each round waits the full time with exactly the limit
in flight. A fan-out that starts one call too many is caught.
Wrap your fake in a few lines:
func (f *fake) Run(ctx context.Context, req Request) (Result, error) {
defer f.calls.Enter()()
return f.answer(ctx, req)
}
fake := &uptime{}
fake.calls.Hold = 3
fake.calls.Patience = time.Minute
fanout.Each(context.Background(), 3, 3, func(i int) {
fake.Ask(fmt.Sprintf("exe%02d", i+1))
})
fmt.Println(fake.calls.Peak(), fake.calls.Started())3 3fanout/fanouttest/example_test.go. CI runs it and checks its output.fake := &uptime{}
fake.calls.Hold = 2
fake.calls.Patience = time.Millisecond
fanout.Each(context.Background(), 3, 1, func(i int) {
fake.Ask(fmt.Sprintf("exe%02d", i+1))
})
fmt.Println(fake.calls.Peak(), fake.calls.Started())1 3fanout/fanouttest/example_test.go. CI runs it and checks its output.