Skip to content

Commit

Permalink
fix: fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekzyla committed Feb 26, 2025
1 parent d5fdf81 commit aac3db4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .chloggen/fix_update-test-in-kafka-topic-observer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: kafkatopicsobserver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix flaky test case

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [38192]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
19 changes: 17 additions & 2 deletions extension/observer/kafkatopicsobserver/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestCollectEndpointsAllConfigSettings(t *testing.T) {
Details: &observer.KafkaTopic{},
},
}
require.Equal(t, want, kEndpoints)
require.True(t, endpointsEqual(want, kEndpoints))

time.Sleep(5 * time.Second)
kEndpoints = obvs.ListEndpoints()
Expand All @@ -120,9 +120,24 @@ func TestCollectEndpointsAllConfigSettings(t *testing.T) {
Details: &observer.KafkaTopic{},
},
}
require.Equal(t, want, kEndpoints)
require.True(t, endpointsEqual(want, kEndpoints))

err = obvs.Shutdown(context.Background())
require.NoError(t, err)
createKafkaClusterAdmin = originalCreateKafkaClusterAdmin
}

func endpointsEqual(list1, list2 []observer.Endpoint) bool {
topicsList1 := make(map[string]bool)
for _, el := range list1 {
topicsList1[el.Target] = true
}
allPresent := true
for _, el := range list2 {
if _, ok := topicsList1[el.Target]; !ok {
allPresent = false
break
}
}
return allPresent && len(list1) == len(list2)
}

0 comments on commit aac3db4

Please sign in to comment.