Skip to content

Commit

Permalink
Merge pull request #18806 from ghouscht/issue-17329
Browse files Browse the repository at this point in the history
chore(e2e): extend logging test to 3 node cluster
  • Loading branch information
ahrtr authored Oct 30, 2024
2 parents 36d785d + cb19f64 commit 10de4d6
Showing 1 changed file with 56 additions and 29 deletions.
85 changes: 56 additions & 29 deletions tests/e2e/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,66 @@ import (
)

func TestNoErrorLogsDuringNormalOperations(t *testing.T) {
e2e.BeforeTest(t)
ctx := context.TODO()
tests := []struct {
name string
clusterSize int
allowedErrors map[string]bool
}{
{
name: "single node cluster",
clusterSize: 1,
allowedErrors: map[string]bool{"setting up serving from embedded etcd failed.": true},
},
{
name: "three node cluster",
clusterSize: 3,
allowedErrors: map[string]bool{"setting up serving from embedded etcd failed.": true},
},
}

epc, err := e2e.NewEtcdProcessCluster(ctx, t,
e2e.WithClusterSize(1),
e2e.WithLogLevel("debug"),
)
require.NoError(t, err)
defer epc.Close()
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
e2e.BeforeTest(t)
ctx := context.TODO()

logs := epc.Procs[0].Logs()
time.Sleep(time.Second)
if err = epc.Close(); err != nil {
t.Fatalf("error closing etcd processes (%v)", err)
}
var entry logEntry
lines := logs.Lines()
if len(lines) == 0 {
t.Errorf("Expected at least one log line")
}
epc, err := e2e.NewEtcdProcessCluster(ctx, t,
e2e.WithClusterSize(tc.clusterSize),
e2e.WithLogLevel("debug"),
)
require.NoError(t, err)
defer epc.Close()

require.Lenf(t, epc.Procs, tc.clusterSize, "embedded etcd cluster process count is not as expected")

// Collect the handle of logs before closing the processes.
var logHandles []e2e.LogsExpect
for i := range tc.clusterSize {
logHandles = append(logHandles, epc.Procs[i].Logs())
}

time.Sleep(time.Second)
err = epc.Close()
require.NoErrorf(t, err, "closing etcd processes")

// Now that the processes are closed we can collect all log lines. This must happen after closing, else we
// might not get all log lines.
var lines []string
for _, h := range logHandles {
lines = append(lines, h.Lines()...)
}
require.NotEmptyf(t, lines, "expected at least one log line")

allowedErrors := map[string]bool{"setting up serving from embedded etcd failed.": true}
var entry logEntry
for _, line := range lines {
err := json.Unmarshal([]byte(line), &entry)
require.NoErrorf(t, err, "parse log line as json, line: %s", line)

for _, line := range lines {
err := json.Unmarshal([]byte(line), &entry)
if err != nil {
t.Errorf("Failed to parse log line as json, err: %q, line: %s", err, line)
continue
}
if allowedErrors[entry.Message] {
continue
}
if tc.allowedErrors[entry.Message] {
continue
}

require.NotEqual(t, "error", entry.Level)
require.NotEqualf(t, "error", entry.Level, "error level log message found: %s", line)
}
})
}
}

0 comments on commit 10de4d6

Please sign in to comment.