From bdd011be30831e5b1924ba9c3e939894e6e8bcc9 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 10 Jul 2020 21:55:54 +0300 Subject: [PATCH] test: update events test with more flow control Some of the event tests rely on publishing more events than buffer capacity, so consumers should be able to keep up with the producer to avoid hitting buffer overrun. Producer was rate-limited already, now adding rate limiting for consumer with higher burst, it should allow consumers to reach blocked state, but syncronizes them a bit with each other. Signed-off-by: Andrey Smirnov --- .../app/machined/pkg/runtime/v1alpha1/v1alpha1_events_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_events_test.go b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_events_test.go index c3a513637..e87dcaa5b 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_events_test.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_events_test.go @@ -79,6 +79,8 @@ func TestEvents_Publish(t *testing.T) { if err := e.Watch(func(events <-chan runtime.Event) { defer wg.Done() + l := rate.NewLimiter(500, tt.cap*8/10) + for j := 0; j < tt.messages; j++ { event, ok := <-events @@ -97,6 +99,8 @@ func TestEvents_Publish(t *testing.T) { } atomic.AddUint32(&got, 1) + + _ = l.Wait(context.Background()) //nolint: errcheck } }); err != nil { t.Errorf("Watch error %s", err)