Skip to content

Commit 463615d

Browse files
authored
Merge pull request #18809 from ghouscht/backport-3.4-no-error-logs-test
[3.4] chore(e2e): backport TestNoErrorLogsDuringNormalOperations test
2 parents 47b5f07 + c989098 commit 463615d

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

pkg/expect/expect.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,9 @@ func (ep *ExpectProcess) Send(command string) error {
171171
func (ep *ExpectProcess) IsRunning() bool {
172172
return ep.cmd != nil
173173
}
174+
175+
func (ep *ExpectProcess) Lines() []string {
176+
ep.mu.Lock()
177+
defer ep.mu.Unlock()
178+
return ep.lines
179+
}

tests/e2e/etcd_process.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type etcdProcess interface {
6262

6363
type logsExpect interface {
6464
Expect(string) (string, error)
65+
Lines() []string
6566
}
6667

6768
type etcdServerProcess struct {

tests/e2e/logging_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
"testing"
19+
"time"
20+
21+
"github.com/stretchr/testify/require"
22+
)
23+
24+
func TestNoErrorLogsDuringNormalOperations(t *testing.T) {
25+
tests := []struct {
26+
name string
27+
clusterSize int
28+
}{
29+
{
30+
name: "single node cluster",
31+
clusterSize: 1,
32+
},
33+
{
34+
name: "three node cluster",
35+
clusterSize: 3,
36+
},
37+
}
38+
39+
for _, tc := range tests {
40+
t.Run(tc.name, func(t *testing.T) {
41+
epc, err := newEtcdProcessCluster(t,
42+
&etcdProcessClusterConfig{
43+
debug: true,
44+
clusterSize: tc.clusterSize,
45+
},
46+
)
47+
require.NoError(t, err)
48+
defer epc.Close()
49+
50+
require.Lenf(t, epc.procs, tc.clusterSize, "embedded etcd cluster process count is not as expected")
51+
52+
// Collect the handle of logs before closing the processes.
53+
var logHandles []logsExpect
54+
for i := range tc.clusterSize {
55+
logHandles = append(logHandles, epc.procs[i].Logs())
56+
}
57+
58+
time.Sleep(time.Second)
59+
err = epc.Close()
60+
require.NoErrorf(t, err, "closing etcd processes")
61+
62+
// Now that the processes are closed we can collect all log lines. This must happen after closing, else we
63+
// might not get all log lines.
64+
var lines []string
65+
for _, h := range logHandles {
66+
lines = append(lines, h.Lines()...)
67+
}
68+
require.NotEmptyf(t, lines, "expected at least one log line")
69+
70+
for _, line := range lines {
71+
require.NotContainsf(t, line, "ERROR:", "error level log line found: %s", line)
72+
}
73+
})
74+
}
75+
}

0 commit comments

Comments
 (0)