mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Merge pull request #14618 from machine424/para
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (0) (push) Waiting to run
CI / Build Prometheus for common architectures (1) (push) Waiting to run
CI / Build Prometheus for common architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (0) (push) Waiting to run
CI / Build Prometheus for all architectures (1) (push) Waiting to run
CI / Build Prometheus for all architectures (10) (push) Waiting to run
CI / Build Prometheus for all architectures (11) (push) Waiting to run
CI / Build Prometheus for all architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (3) (push) Waiting to run
CI / Build Prometheus for all architectures (4) (push) Waiting to run
CI / Build Prometheus for all architectures (5) (push) Waiting to run
CI / Build Prometheus for all architectures (6) (push) Waiting to run
CI / Build Prometheus for all architectures (7) (push) Waiting to run
CI / Build Prometheus for all architectures (8) (push) Waiting to run
CI / Build Prometheus for all architectures (9) (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (0) (push) Waiting to run
CI / Build Prometheus for common architectures (1) (push) Waiting to run
CI / Build Prometheus for common architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (0) (push) Waiting to run
CI / Build Prometheus for all architectures (1) (push) Waiting to run
CI / Build Prometheus for all architectures (10) (push) Waiting to run
CI / Build Prometheus for all architectures (11) (push) Waiting to run
CI / Build Prometheus for all architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (3) (push) Waiting to run
CI / Build Prometheus for all architectures (4) (push) Waiting to run
CI / Build Prometheus for all architectures (5) (push) Waiting to run
CI / Build Prometheus for all architectures (6) (push) Waiting to run
CI / Build Prometheus for all architectures (7) (push) Waiting to run
CI / Build Prometheus for all architectures (8) (push) Waiting to run
CI / Build Prometheus for all architectures (9) (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
test(cmd/prometheus): speed up test execution by t.Parallel() when possible
This commit is contained in:
commit
6b36a5592a
|
@ -125,6 +125,7 @@ func TestFailedStartupExitCode(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping test in short mode.")
|
t.Skip("skipping test in short mode.")
|
||||||
}
|
}
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
fakeInputFile := "fake-input-file"
|
fakeInputFile := "fake-input-file"
|
||||||
expectedExitStatus := 2
|
expectedExitStatus := 2
|
||||||
|
@ -211,83 +212,125 @@ func TestWALSegmentSizeBounds(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping test in short mode.")
|
t.Skip("skipping test in short mode.")
|
||||||
}
|
}
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
for size, expectedExitStatus := range map[string]int{"9MB": 1, "257MB": 1, "10": 2, "1GB": 1, "12MB": 0} {
|
for _, tc := range []struct {
|
||||||
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"))
|
size string
|
||||||
|
exitCode int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
size: "9MB",
|
||||||
|
exitCode: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
size: "257MB",
|
||||||
|
exitCode: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
size: "10",
|
||||||
|
exitCode: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
size: "1GB",
|
||||||
|
exitCode: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
size: "12MB",
|
||||||
|
exitCode: 0,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(tc.size, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
prom := exec.Command(promPath, "-test.main", "--storage.tsdb.wal-segment-size="+tc.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()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
go func() {
|
go func() {
|
||||||
slurp, _ := io.ReadAll(stderr)
|
slurp, _ := io.ReadAll(stderr)
|
||||||
t.Log(string(slurp))
|
t.Log(string(slurp))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = prom.Start()
|
err = prom.Start()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if expectedExitStatus == 0 {
|
if tc.exitCode == 0 {
|
||||||
done := make(chan error, 1)
|
done := make(chan error, 1)
|
||||||
go func() { done <- prom.Wait() }()
|
go func() { done <- prom.Wait() }()
|
||||||
select {
|
select {
|
||||||
case err := <-done:
|
case err := <-done:
|
||||||
require.Fail(t, "prometheus should be still running: %v", err)
|
require.Fail(t, "prometheus should be still running: %v", err)
|
||||||
case <-time.After(startupTime):
|
case <-time.After(startupTime):
|
||||||
prom.Process.Kill()
|
prom.Process.Kill()
|
||||||
<-done
|
<-done
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
err = prom.Wait()
|
err = prom.Wait()
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
var exitError *exec.ExitError
|
var exitError *exec.ExitError
|
||||||
require.ErrorAs(t, err, &exitError)
|
require.ErrorAs(t, err, &exitError)
|
||||||
status := exitError.Sys().(syscall.WaitStatus)
|
status := exitError.Sys().(syscall.WaitStatus)
|
||||||
require.Equal(t, expectedExitStatus, status.ExitStatus())
|
require.Equal(t, tc.exitCode, status.ExitStatus())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.")
|
||||||
}
|
}
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
for size, expectedExitStatus := range map[string]int{"512KB": 1, "1MB": 0} {
|
for _, tc := range []struct {
|
||||||
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"))
|
size string
|
||||||
|
exitCode int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
size: "512KB",
|
||||||
|
exitCode: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
size: "1MB",
|
||||||
|
exitCode: 0,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(tc.size, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
prom := exec.Command(promPath, "-test.main", "--storage.tsdb.max-block-chunk-segment-size="+tc.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()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
go func() {
|
go func() {
|
||||||
slurp, _ := io.ReadAll(stderr)
|
slurp, _ := io.ReadAll(stderr)
|
||||||
t.Log(string(slurp))
|
t.Log(string(slurp))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = prom.Start()
|
err = prom.Start()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if expectedExitStatus == 0 {
|
if tc.exitCode == 0 {
|
||||||
done := make(chan error, 1)
|
done := make(chan error, 1)
|
||||||
go func() { done <- prom.Wait() }()
|
go func() { done <- prom.Wait() }()
|
||||||
select {
|
select {
|
||||||
case err := <-done:
|
case err := <-done:
|
||||||
require.Fail(t, "prometheus should be still running: %v", err)
|
require.Fail(t, "prometheus should be still running: %v", err)
|
||||||
case <-time.After(startupTime):
|
case <-time.After(startupTime):
|
||||||
prom.Process.Kill()
|
prom.Process.Kill()
|
||||||
<-done
|
<-done
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
err = prom.Wait()
|
err = prom.Wait()
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
var exitError *exec.ExitError
|
var exitError *exec.ExitError
|
||||||
require.ErrorAs(t, err, &exitError)
|
require.ErrorAs(t, err, &exitError)
|
||||||
status := exitError.Sys().(syscall.WaitStatus)
|
status := exitError.Sys().(syscall.WaitStatus)
|
||||||
require.Equal(t, expectedExitStatus, status.ExitStatus())
|
require.Equal(t, tc.exitCode, status.ExitStatus())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,6 +396,8 @@ func getCurrentGaugeValuesFor(t *testing.T, reg prometheus.Gatherer, metricNames
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAgentSuccessfulStartup(t *testing.T) {
|
func TestAgentSuccessfulStartup(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
prom := exec.Command(promPath, "-test.main", "--agent", "--web.listen-address=0.0.0.0:0", "--config.file="+agentConfig)
|
prom := exec.Command(promPath, "-test.main", "--agent", "--web.listen-address=0.0.0.0:0", "--config.file="+agentConfig)
|
||||||
require.NoError(t, prom.Start())
|
require.NoError(t, prom.Start())
|
||||||
|
|
||||||
|
@ -371,6 +416,8 @@ func TestAgentSuccessfulStartup(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAgentFailedStartupWithServerFlag(t *testing.T) {
|
func TestAgentFailedStartupWithServerFlag(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
prom := exec.Command(promPath, "-test.main", "--agent", "--storage.tsdb.path=.", "--web.listen-address=0.0.0.0:0", "--config.file="+promConfig)
|
prom := exec.Command(promPath, "-test.main", "--agent", "--storage.tsdb.path=.", "--web.listen-address=0.0.0.0:0", "--config.file="+promConfig)
|
||||||
|
|
||||||
output := bytes.Buffer{}
|
output := bytes.Buffer{}
|
||||||
|
@ -398,6 +445,8 @@ func TestAgentFailedStartupWithServerFlag(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAgentFailedStartupWithInvalidConfig(t *testing.T) {
|
func TestAgentFailedStartupWithInvalidConfig(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
prom := exec.Command(promPath, "-test.main", "--agent", "--web.listen-address=0.0.0.0:0", "--config.file="+promConfig)
|
prom := exec.Command(promPath, "-test.main", "--agent", "--web.listen-address=0.0.0.0:0", "--config.file="+promConfig)
|
||||||
require.NoError(t, prom.Start())
|
require.NoError(t, prom.Start())
|
||||||
|
|
||||||
|
@ -419,6 +468,7 @@ func TestModeSpecificFlags(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping test in short mode.")
|
t.Skip("skipping test in short mode.")
|
||||||
}
|
}
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
mode string
|
mode string
|
||||||
|
@ -433,6 +483,7 @@ func TestModeSpecificFlags(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range testcases {
|
for _, tc := range testcases {
|
||||||
t.Run(fmt.Sprintf("%s mode with option %s", tc.mode, tc.arg), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%s mode with option %s", tc.mode, tc.arg), func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
args := []string{"-test.main", tc.arg, t.TempDir(), "--web.listen-address=0.0.0.0:0"}
|
args := []string{"-test.main", tc.arg, t.TempDir(), "--web.listen-address=0.0.0.0:0"}
|
||||||
|
|
||||||
if tc.mode == "agent" {
|
if tc.mode == "agent" {
|
||||||
|
@ -484,6 +535,8 @@ func TestDocumentation(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
}
|
}
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
@ -508,6 +561,8 @@ func TestDocumentation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRwProtoMsgFlagParser(t *testing.T) {
|
func TestRwProtoMsgFlagParser(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
defaultOpts := config.RemoteWriteProtoMsgs{
|
defaultOpts := config.RemoteWriteProtoMsgs{
|
||||||
config.RemoteWriteProtoMsgV1, config.RemoteWriteProtoMsgV2,
|
config.RemoteWriteProtoMsgV1, config.RemoteWriteProtoMsgV2,
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ func TestStartupInterrupt(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping test in short mode.")
|
t.Skip("skipping test in short mode.")
|
||||||
}
|
}
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
port := fmt.Sprintf(":%d", testutil.RandomUnprivilegedPort(t))
|
port := fmt.Sprintf(":%d", testutil.RandomUnprivilegedPort(t))
|
||||||
|
|
||||||
|
|
|
@ -456,6 +456,7 @@ func TestQueryLog(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping test in short mode.")
|
t.Skip("skipping test in short mode.")
|
||||||
}
|
}
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -474,6 +475,7 @@ func TestQueryLog(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run(p.String(), func(t *testing.T) {
|
t.Run(p.String(), func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
p.run(t)
|
p.run(t)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue