Skip to content

fix(e2e): address flakiness for internal/events test#7804

Merged
wozniakjan merged 1 commit into
kedacore:mainfrom
wozniakjan:fix/flaky-events-e2e
May 31, 2026
Merged

fix(e2e): address flakiness for internal/events test#7804
wozniakjan merged 1 commit into
kedacore:mainfrom
wozniakjan:fix/flaky-events-e2e

Conversation

@wozniakjan

Copy link
Copy Markdown
Member

The events e2e test asserted events at fixed positions in a list sorted by .metadata.creationTimestamp. KEDA emits several events for a single ScaledObject/ScaledJob within the same second, and events.k8s.io creationTimestamp only has 1s granularity, so same-second events sort non-deterministically. After #7781 migrated event recording to events.k8s.io, the already flaky test became failing almost always.

Match the expected reason/note pair against any event emitted for the resource instead of a fixed index, removing the ordering dependency.

The events e2e test asserted events at fixed positions in a list sorted
by .metadata.creationTimestamp. KEDA emits several events for a single
ScaledObject/ScaledJob within the same second, and events.k8s.io
creationTimestamp only has 1s granularity, so same-second events sort
non-deterministically. After kedacore#7781 migrated event recording to
events.k8s.io, "Started scalers watch" [1] and "ScaledJob is ready for
scaling" [2] started swapping positions, failing the test every night.

Match the expected reason/note pair against any event emitted for the
resource instead of a fixed index, removing the ordering dependency.

Signed-off-by: Jan Wozniak <[email protected]>
@wozniakjan wozniakjan requested a review from a team as a code owner May 31, 2026 10:27
@wozniakjan wozniakjan requested a review from Copilot May 31, 2026 10:27
@github-actions

Copy link
Copy Markdown

Thank you for your contribution! 🙏

Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected.

While you are waiting, make sure to:

  • Add an entry in our changelog in alphabetical order and link related issue
  • Update the documentation, if needed
  • Add unit & e2e tests for your changes
  • GitHub checks are passing
  • Is the DCO check failing? Here is how you can fix DCO issues

Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient.

Learn more about our contribution guide.

@keda-automation keda-automation requested a review from a team May 31, 2026 10:27
@snyk-io

snyk-io Bot commented May 31, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@wozniakjan

wozniakjan commented May 31, 2026

Copy link
Copy Markdown
Member Author

/run-e2e internals/events
Update: You can check the progress here

passed tests: 1
Execution of tests/internals/events/events_test.go, has passed after "two" attempts
failed tests: 0

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes flakiness in the events e2e test by removing the dependence on event ordering. Previously, the test asserted events at fixed indices in a list sorted by creationTimestamp, but since events.k8s.io events emitted within the same second sort non-deterministically (creationTimestamp has 1s granularity), the test became unreliable after the migration to events.k8s.io in #7781. The test now scans all matching events for the expected reason/note pair.

Changes:

  • Removed the index parameter from checkingEvent and updated all call sites.
  • Replaced the jsonpath index-based query with a JSON dump and a scan over all items.
  • Added encoding/json import for unmarshaling event lists.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wozniakjan wozniakjan merged commit b130527 into kedacore:main May 31, 2026
24 checks passed
shcherbak pushed a commit to shcherbak/keda that referenced this pull request Jun 3, 2026
)

The events e2e test asserted events at fixed positions in a list sorted
by .metadata.creationTimestamp. KEDA emits several events for a single
ScaledObject/ScaledJob within the same second, and events.k8s.io
creationTimestamp only has 1s granularity, so same-second events sort
non-deterministically. After kedacore#7781 migrated event recording to
events.k8s.io, "Started scalers watch" [1] and "ScaledJob is ready for
scaling" [2] started swapping positions, failing the test every night.

Match the expected reason/note pair against any event emitted for the
resource instead of a fixed index, removing the ordering dependency.

Signed-off-by: Jan Wozniak <[email protected]>
Signed-off-by: Yurii Shcherbak <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants