mirror of https://github.com/grafana/loki
test(promtail): Fix flaky test with promtail bind port. (#6859)
* test(promtail): Fix flaky test with promtail bind port.
You cannot run promtail tests if there is already running promtail in your local.
e.g:
```
$ go test -run TestPromtail ./clients/pkg/promtail/
```
It gives you error
```
--- FAIL: TestPromtail (0.02s)
promtail_test.go:112: error creating promtail listen tcp 127.0.0.1:9080: bind: address already in use
FAIL
FAIL github.com/grafana/loki/clients/pkg/promtail 0.043s
```
Cause for the error is, test uses static default port (the same we use for promtail normally) in tests.
This is not **too** annonying if seen in isolation. But mainly annoying in two cases particularly
1. Hard to run tests parallely in general with these kind of static ports
2. These are causing some real problems in some integeration tests on GEL which starts docker-compose to run some test suites and
even stopping containers won't release ports soon enough making CI fail randomly.
This PR takes advantage of Go idiom of passing `port=0` to http (and also grpc) servers enforce Go's `net` package to bind some unused random ports. Making each test run choose random ports
enabling easy running theses tests in parallel.
NOTE: This PR also contains upgrade in `common/server` package that made this fix possible.
https://github.com/weaveworks/common/pull/249
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
* go mod tidy
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
pull/6865/head
parent
e372383f0d
commit
e8b44172d8
Loading…
Reference in new issue