Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ReallyLiri committed Oct 31, 2021
1 parent d11b046 commit 9cece1c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 39 deletions.
37 changes: 5 additions & 32 deletions diag/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,12 @@ func TestEventState_NodeProblemDetector(t *testing.T) {

now := asTime("2021-10-14T06:30:00Z")

state, err := testContext(now).eventState(&events[0])
require.Nil(t, err)
log.Debugf("%v) %v", 0, state)
require.False(t, state.isHealthy())
require.NotEmpty(t, state.name.name)
messages := strings.Split(state.cleanMessage(), "\n")
assert.Equal(t, 1, len(messages))
assert.Equal(t, "Event by sysctl-monitor: NodeSysctlChange x29 since 07 Oct 21 05:24 UTC, 1 week ago (last seen 1 hour ago)", messages[0])

state, err = testContext(now).eventState(&events[1])
state, err := testContext(now).eventState(&events[1])
require.Nil(t, err)
log.Debugf("%v) %v", 1, state)
require.False(t, state.isHealthy())
require.NotEmpty(t, state.name.name)
messages = strings.Split(state.cleanMessage(), "\n")
messages := strings.Split(state.cleanMessage(), "\n")
assert.Equal(t, 2, len(messages))
assert.Equal(t, "Event by kernel-monitor: KernelOops since 14 Oct 21 06:10 UTC, 19 minutes ago:", messages[0])
assert.Equal(t, "\tkernel: BUG: unable to handle kernel NULL pointer dereference at TESTING", messages[1])
Expand Down Expand Up @@ -193,8 +184,8 @@ func TestEventState_LivenessFailed(t *testing.T) {
require.False(t, state.isHealthy())
require.NotEmpty(t, state.name.name)
messages := strings.Split(state.cleanMessage(), "\n")
require.True(t, len(messages) >= 2)
require.True(t, len(messages) <= 5)
require.True(t, len(messages) >= 2, len(messages))
require.True(t, len(messages) <= 9, len(messages))
require.True(t, strings.HasPrefix(messages[0], "Event by kubelet: "))
require.True(t, strings.Index(messages[0], "Unhealthy ") > 0 || strings.Index(messages[0], "BackOff ") > 0)
require.True(t,
Expand All @@ -214,25 +205,7 @@ func TestEventState_EndpointsWarning(t *testing.T) {

now := asTime("2021-10-31T08:45:30Z")

warningIndexes := []int{
24,
}

skipIndexes := internal.ToMap(warningIndexes)

verifyEventsHealthyExcept(t, events, now, skipIndexes)

state, err := testContext(now).eventState(&events[24])
require.Nil(t, err)
log.Debug(state.String())
require.False(t, state.isHealthy())
assert.Equal(t, "api-nodeport", state.name.name)
assert.Equal(t, "Endpoints", state.name.kind)
assert.Equal(t, "ci", state.name.namespace)
messages := strings.Split(state.cleanMessage(), "\n")
assert.Equal(t, 2, len(messages))
assert.Equal(t, "Event by endpoint-controller: FailedToUpdateEndpoint since 31 Oct 21 08:29 UTC, 16 minutes ago:", messages[0])
assert.Equal(t, "\tFailed to update endpoint ch/api-nodeport: Operation cannot be fulfilled on endpoints \"api-nodeport\": the object has been modified; please apply your changes to the latest version and try again", messages[1])
verifyEventsHealthyExcept(t, events, now, map[int]bool{})
}

func TestEventState_StartedEventsShouldBeIgnored(t *testing.T) {
Expand Down
8 changes: 3 additions & 5 deletions diag/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ func hash(entityName entityName, message string) string {
return fmt.Sprintf("%x", asBytes)
}

var dedupThreshold = 65

func forI(from int, until int, action func(int) bool) {
func forRange(from int, until int, action func(int) bool) {
i := from
for {
if i >= until {
Expand Down Expand Up @@ -227,9 +225,9 @@ func dedup(items []interface{}, dedupOnValue func(interface{}) string, similarit
}

var indexes []int
forI(0, len(values), func(i int) bool {
forRange(0, len(values), func(i int) bool {
anySimilar := false
forI(0, i, func(j int) bool {
forRange(0, i, func(j int) bool {
distance := levenshtein.Distance(values[i], values[j])
score := 1 - float64(distance)/float64(max(len(values[i]), len(values[j])))
if score >= similarityThreshold {
Expand Down
2 changes: 0 additions & 2 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ var expectedFormatsFirstRun = []string{
Container test-2-broken-image still waiting due to *
Event by kubelet: Failed x* since * (last seen * ago):
Failed to pull image "nginx:l4t3st": rpc error: code = Unknown desc = Error response from daemon: manifest for nginx:l4t3st not found: manifest unknown: manifest unknown
Event by kubelet: Failed x* since * (last seen * ago):
Error: ErrImagePull
Event by kubelet: Failed x* since * (last seen * ago):
Error: ImagePullBackOff`,

Expand Down

0 comments on commit 9cece1c

Please sign in to comment.