From a9580b4db5fb7576c5a5f3706aa80b0f68124936 Mon Sep 17 00:00:00 2001 From: Tiago Queiroz Date: Mon, 25 Mar 2024 09:22:05 +0100 Subject: [PATCH] Fix failing tests The pipeline client used in some tests could not have its Close method called more than once, given the changes introduces in the previous commits, some test scenarios called it more than once. This is fixed by using a sync.Once in ChanClient.Close. --- libbeat/publisher/testing/testing.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libbeat/publisher/testing/testing.go b/libbeat/publisher/testing/testing.go index 0c64e4601d5e..09c1fdb6b116 100644 --- a/libbeat/publisher/testing/testing.go +++ b/libbeat/publisher/testing/testing.go @@ -19,6 +19,8 @@ package testing // ChanClient implements Client interface, forwarding published events to some import ( + "sync" + "github.com/elastic/beats/v7/libbeat/beat" ) @@ -31,6 +33,7 @@ type ChanClient struct { done chan struct{} Channel chan beat.Event publishCallback func(event beat.Event) + closeOnce sync.Once } func PublisherWithClient(client beat.Client) beat.Pipeline { @@ -68,7 +71,9 @@ func NewChanClientWith(ch chan beat.Event) *ChanClient { } func (c *ChanClient) Close() error { - close(c.done) + c.closeOnce.Do(func() { + close(c.done) + }) return nil }