Skip to content

Commit 1b88fc4

Browse files
authored
Merge pull request #18807 from ghouscht/backport-3.5-no-error-logs-test
[3.5] chore(e2e): backport TestNoErrorLogsDuringNormalOperations test
2 parents 23f887a + 5ec08a2 commit 1b88fc4

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

tests/e2e/logging_test.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2024 The etcd Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package e2e
16+
17+
import (
18+
"encoding/json"
19+
"testing"
20+
"time"
21+
22+
"github.com/stretchr/testify/require"
23+
24+
"go.etcd.io/etcd/tests/v3/framework/e2e"
25+
)
26+
27+
func TestNoErrorLogsDuringNormalOperations(t *testing.T) {
28+
tests := []struct {
29+
name string
30+
clusterSize int
31+
allowedErrors map[string]bool
32+
}{
33+
{
34+
name: "single node cluster",
35+
clusterSize: 1,
36+
allowedErrors: map[string]bool{},
37+
},
38+
{
39+
name: "three node cluster",
40+
clusterSize: 3,
41+
allowedErrors: map[string]bool{},
42+
},
43+
}
44+
45+
for _, tc := range tests {
46+
t.Run(tc.name, func(t *testing.T) {
47+
e2e.BeforeTest(t)
48+
49+
epc, err := e2e.NewEtcdProcessCluster(t,
50+
&e2e.EtcdProcessClusterConfig{
51+
LogLevel: "debug",
52+
ClusterSize: tc.clusterSize,
53+
},
54+
)
55+
require.NoError(t, err)
56+
defer epc.Close()
57+
58+
require.Lenf(t, epc.Procs, tc.clusterSize, "embedded etcd cluster process count is not as expected")
59+
60+
// Collect the handle of logs before closing the processes.
61+
var logHandles []e2e.LogsExpect
62+
for i := range tc.clusterSize {
63+
logHandles = append(logHandles, epc.Procs[i].Logs())
64+
}
65+
66+
time.Sleep(time.Second)
67+
err = epc.Close()
68+
require.NoErrorf(t, err, "closing etcd processes")
69+
70+
// Now that the processes are closed we can collect all log lines. This must happen after closing, else we
71+
// might not get all log lines.
72+
var lines []string
73+
for _, h := range logHandles {
74+
lines = append(lines, h.Lines()...)
75+
}
76+
require.NotEmptyf(t, lines, "expected at least one log line")
77+
78+
var entry logEntry
79+
for _, line := range lines {
80+
err := json.Unmarshal([]byte(line), &entry)
81+
require.NoErrorf(t, err, "parse log line as json, line: %s", line)
82+
83+
if tc.allowedErrors[entry.Message] {
84+
continue
85+
}
86+
87+
require.NotEqualf(t, "error", entry.Level, "error level log message found: %s", line)
88+
}
89+
})
90+
}
91+
}

0 commit comments

Comments
 (0)