Fix failing test `TestGlobWithMultipleFiles` in pkg/promtail/targets (#466)

TestClient used for watching log file events appends logs to a list
Due to race condition some of the logs added to it goes missing
Adding a Mutex to it to lock messages before adding logs to it
pull/467/head
Sandeep Sukhani 6 years ago committed by Ed
parent 63be9c24c5
commit bc571c54c9
  1. 7
      pkg/promtail/targets/filetarget_test.go

@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"sort"
"sync"
"testing"
"time"
@ -724,11 +725,15 @@ func TestMissing(t *testing.T) {
type TestClient struct {
log log.Logger
messages []string
sync.Mutex
}
func (c *TestClient) Handle(ls model.LabelSet, t time.Time, s string) error {
c.messages = append(c.messages, s)
level.Debug(c.log).Log("msg", "received log", "log", s)
c.Lock()
defer c.Unlock()
c.messages = append(c.messages, s)
return nil
}

Loading…
Cancel
Save