Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Various improvements to unit tests. #559

Merged
merged 3 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

[[constraint]]
name = "github.com/weaveworks/common"
branch = "master"
source = "https://github.com/tomwilkie/weaveworks-common"
branch = "server-listen-addr"

[[constraint]]
name = "gopkg.in/fsnotify.v1"
Expand Down
6 changes: 2 additions & 4 deletions pkg/ingester/flush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ package ingester

import (
"fmt"
"os"
"sort"
"sync"
"testing"
"time"

"github.com/cortexproject/cortex/pkg/chunk"
"github.com/cortexproject/cortex/pkg/ring"
"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/go-kit/kit/log"
"github.com/grafana/loki/pkg/chunkenc"
"github.com/grafana/loki/pkg/logproto"
"github.com/prometheus/common/model"
Expand All @@ -27,7 +24,7 @@ const (
)

func init() {
util.Logger = log.NewLogfmtLogger(os.Stdout)
//util.Logger = log.NewLogfmtLogger(os.Stdout)
}

func TestChunkFlushingIdle(t *testing.T) {
Expand Down Expand Up @@ -81,6 +78,7 @@ func defaultIngesterTestConfig() Config {
cfg.LifecyclerConfig.ListenPort = func(i int) *int { return &i }(0)
cfg.LifecyclerConfig.Addr = "localhost"
cfg.LifecyclerConfig.ID = "localhost"
cfg.LifecyclerConfig.FinalSleep = 0
return cfg
}

Expand Down
11 changes: 1 addition & 10 deletions pkg/ingester/ingester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,10 @@ import (
"google.golang.org/grpc"

"github.com/cortexproject/cortex/pkg/chunk"
"github.com/cortexproject/cortex/pkg/ring"
"github.com/cortexproject/cortex/pkg/util/flagext"
)

func TestIngester(t *testing.T) {
var ingesterConfig Config
flagext.DefaultValues(&ingesterConfig)
ingesterConfig.LifecyclerConfig.RingConfig.Mock = ring.NewInMemoryKVClient()
ingesterConfig.LifecyclerConfig.NumTokens = 1
ingesterConfig.LifecyclerConfig.ListenPort = func(i int) *int { return &i }(0)
ingesterConfig.LifecyclerConfig.Addr = "localhost"
ingesterConfig.LifecyclerConfig.ID = "localhost"

ingesterConfig := defaultIngesterTestConfig()
store := &mockStore{
chunks: map[string][]chunk.Chunk{},
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/promtail/promtail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import (
"github.com/grafana/loki/pkg/promtail/scrape"
)

const httpTestPort = 9080

func TestPromtail(t *testing.T) {

// Setup.

w := log.NewSyncWriter(os.Stderr)
logger := log.NewLogfmtLogger(w)
logger = level.NewFilter(logger, level.AllowInfo())
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestPromtail(t *testing.T) {
}
}()
go func() {
if err = http.ListenAndServe("127.0.0.1:3100", nil); err != nil {
if err = http.ListenAndServe("localhost:3100", nil); err != nil {
err = errors.Wrap(err, "Failed to start web server to receive logs")
}
}()
Expand Down Expand Up @@ -398,7 +399,7 @@ func (h *testServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

func getPromMetrics(t *testing.T) ([]byte, string) {
resp, err := http.Get("http://localhost:80/metrics")
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/metrics", httpTestPort))
if err != nil {
t.Fatal("Could not query metrics endpoint", err)
}
Expand Down Expand Up @@ -457,6 +458,11 @@ func buildTestConfig(t *testing.T, positionsFileName string, logDirName string)
// Init everything with default values.
flagext.RegisterFlags(&cfg)

// Make promtail listen on localhost to avoid prompts on MacOS.
cfg.ServerConfig.HTTPListenHost = "localhost"
cfg.ServerConfig.HTTPListenPort = httpTestPort
cfg.ServerConfig.GRPCListenHost = "localhost"

// Override some of those defaults
cfg.ClientConfig.URL = clientURL
cfg.ClientConfig.BatchWait = 10 * time.Millisecond
Expand Down
5 changes: 5 additions & 0 deletions vendor/github.com/weaveworks/common/logging/level.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions vendor/github.com/weaveworks/common/server/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.