mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
cmd/prometheus: randomize test port and isolate test data directory
Between the tests. This enables parallelizing those tests, which should cut the test execution time. Signed-off-by: Mateusz Gozdek <mgozdekof@gmail.com>
This commit is contained in:
parent
5e002dec68
commit
fa1b14e146
|
@ -41,7 +41,6 @@ var (
|
||||||
promPath = os.Args[0]
|
promPath = os.Args[0]
|
||||||
promConfig = filepath.Join("..", "..", "documentation", "examples", "prometheus.yml")
|
promConfig = filepath.Join("..", "..", "documentation", "examples", "prometheus.yml")
|
||||||
agentConfig = filepath.Join("..", "..", "documentation", "examples", "prometheus-agent.yml")
|
agentConfig = filepath.Join("..", "..", "documentation", "examples", "prometheus-agent.yml")
|
||||||
promData = filepath.Join(os.TempDir(), "data")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -57,7 +56,6 @@ func TestMain(m *testing.M) {
|
||||||
os.Setenv("no_proxy", "localhost,127.0.0.1,0.0.0.0,:")
|
os.Setenv("no_proxy", "localhost,127.0.0.1,0.0.0.0,:")
|
||||||
|
|
||||||
exitCode := m.Run()
|
exitCode := m.Run()
|
||||||
os.RemoveAll(promData)
|
|
||||||
os.Exit(exitCode)
|
os.Exit(exitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +205,7 @@ func TestWALSegmentSizeBounds(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for size, expectedExitStatus := range map[string]int{"9MB": 1, "257MB": 1, "10": 2, "1GB": 1, "12MB": 0} {
|
for size, expectedExitStatus := range map[string]int{"9MB": 1, "257MB": 1, "10": 2, "1GB": 1, "12MB": 0} {
|
||||||
prom := exec.Command(promPath, "-test.main", "--storage.tsdb.wal-segment-size="+size, "--web.listen-address=0.0.0.0:0", "--config.file="+promConfig)
|
prom := exec.Command(promPath, "-test.main", "--storage.tsdb.wal-segment-size="+size, "--web.listen-address=0.0.0.0:0", "--config.file="+promConfig, "--storage.tsdb.path="+filepath.Join(t.TempDir(), "data"))
|
||||||
|
|
||||||
// Log stderr in case of failure.
|
// Log stderr in case of failure.
|
||||||
stderr, err := prom.StderrPipe()
|
stderr, err := prom.StderrPipe()
|
||||||
|
@ -245,12 +243,14 @@ func TestWALSegmentSizeBounds(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMaxBlockChunkSegmentSizeBounds(t *testing.T) {
|
func TestMaxBlockChunkSegmentSizeBounds(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping test in short mode.")
|
t.Skip("skipping test in short mode.")
|
||||||
}
|
}
|
||||||
|
|
||||||
for size, expectedExitStatus := range map[string]int{"512KB": 1, "1MB": 0} {
|
for size, expectedExitStatus := range map[string]int{"512KB": 1, "1MB": 0} {
|
||||||
prom := exec.Command(promPath, "-test.main", "--storage.tsdb.max-block-chunk-segment-size="+size, "--web.listen-address=0.0.0.0:0", "--config.file="+promConfig)
|
prom := exec.Command(promPath, "-test.main", "--storage.tsdb.max-block-chunk-segment-size="+size, "--web.listen-address=0.0.0.0:0", "--config.file="+promConfig, "--storage.tsdb.path="+filepath.Join(t.TempDir(), "data"))
|
||||||
|
|
||||||
// Log stderr in case of failure.
|
// Log stderr in case of failure.
|
||||||
stderr, err := prom.StderrPipe()
|
stderr, err := prom.StderrPipe()
|
||||||
|
|
|
@ -31,7 +31,7 @@ func TestStartupInterrupt(t *testing.T) {
|
||||||
t.Skip("skipping test in short mode.")
|
t.Skip("skipping test in short mode.")
|
||||||
}
|
}
|
||||||
|
|
||||||
prom := exec.Command(promPath, "-test.main", "--config.file="+promConfig, "--storage.tsdb.path="+promData)
|
prom := exec.Command(promPath, "-test.main", "--config.file="+promConfig, "--storage.tsdb.path="+t.TempDir())
|
||||||
err := prom.Start()
|
err := prom.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("execution error: %v", err)
|
t.Errorf("execution error: %v", err)
|
||||||
|
|
|
@ -31,6 +31,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type origin int
|
type origin int
|
||||||
|
@ -412,7 +414,6 @@ func TestQueryLog(t *testing.T) {
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
port := 15000
|
|
||||||
for _, host := range []string{"127.0.0.1", "[::1]"} {
|
for _, host := range []string{"127.0.0.1", "[::1]"} {
|
||||||
for _, prefix := range []string{"", "/foobar"} {
|
for _, prefix := range []string{"", "/foobar"} {
|
||||||
for _, enabledAtStart := range []bool{true, false} {
|
for _, enabledAtStart := range []bool{true, false} {
|
||||||
|
@ -422,7 +423,7 @@ func TestQueryLog(t *testing.T) {
|
||||||
host: host,
|
host: host,
|
||||||
enabledAtStart: enabledAtStart,
|
enabledAtStart: enabledAtStart,
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
port: port,
|
port: testutil.RandomUnprivilegedPort(t),
|
||||||
cwd: cwd,
|
cwd: cwd,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue