Skip to content

Commit

Permalink
chore(e2e): extend logging test to 3 node cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Gosteli <[email protected]>
  • Loading branch information
ghouscht committed Oct 29, 2024
1 parent 3696b32 commit cd7b0f9
Showing 1 changed file with 50 additions and 29 deletions.
79 changes: 50 additions & 29 deletions tests/e2e/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,60 @@ 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.Len(t, epc.Procs, tc.clusterSize, "embedded etcd cluster process count is not as expected")

var lines []string
for i := range tc.clusterSize {
lines = append(lines, epc.Procs[i].Logs().Lines()...)
}
require.Greaterf(t, len(lines), 0, "expected at least one log line")

time.Sleep(time.Second)

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

var entry logEntry

allowedErrors := map[string]bool{"setting up serving from embedded etcd failed.": true}
for _, line := range lines {
err := json.Unmarshal([]byte(line), &entry)
require.NoErrorf(t, err, "pare 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 cd7b0f9

Please sign in to comment.