Skip to content

Commit

Permalink
Fix failing test TestGlobWithMultipleFiles in pkg/promtail/targets (g…
Browse files Browse the repository at this point in the history
…rafana#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
  • Loading branch information
sandeepsukhani authored and slim-bean committed Apr 10, 2019
1 parent 63be9c2 commit bc571c5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/promtail/targets/filetarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"sort"
"sync"
"testing"
"time"

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

Expand Down

0 comments on commit bc571c5

Please sign in to comment.