Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
belimawr committed Mar 27, 2024
1 parent 57b8b0d commit a9580b4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libbeat/publisher/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package testing

// ChanClient implements Client interface, forwarding published events to some
import (
"sync"

"github.com/elastic/beats/v7/libbeat/beat"
)

Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit a9580b4

Please sign in to comment.