Skip to content

Conversation

@utkuozdemir
Copy link
Member

Fix two things in the resource asserters:

  1. We were doing a busy state.Get loop in the resource assertions. This was unnecessary to wait for a resource to be created, as we also create a watch, and the moment the resource gets created, we get notified. Changed this logic to follow the same logic with the rest of the assertions on the resource (block on watch events).

  2. This busy wait also produced a test log every single time the resource was not found, producing an excessive number of logs. Remove this log and unify the logic with the rest of the assertions (see fix 1), so that the NotFound logs will also be aggregated/de-duplicated.

Fix two things in the resource asserters:

1. We were doing a busy `state.Get` loop in the resource assertions. This was unnecessary to wait for a resource to be created, as we also create a watch, and the moment the resource gets created, we get notified. Changed this logic to follow the same logic with the rest of the assertions on the resource (block on `watch` events).

2. This busy wait also produced a test log every single time the resource was not found, producing an excessive number of logs. Remove this log and unify the logic with the rest of the assertions (see fix 1), so that the NotFound logs will also be aggregated/de-duplicated.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
@utkuozdemir utkuozdemir requested a review from Copilot July 8, 2025 22:37
@utkuozdemir utkuozdemir self-assigned this Jul 8, 2025
@talos-bot talos-bot moved this to In Review in Planning Jul 8, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

The PR refactors the resource asserters to block on watch events instead of busy-waiting on StateGet, removes excessive NotFound logs, and corrects a typo in the reporting counter.

  • Replace busy StateGet loops with watch-based blocking
  • Remove per-iteration NotFound logging and deduplicate reports
  • Fix typo lastReporedOklastReportedOk
Comments suppressed due to low confidence (1)

pkg/resource/rtestutils/assertions.go:60

  • For NotFound errors you still fall through and call asserter.NoError(err), causing the test to fail immediately instead of retrying. You likely need to continue the loop when state.IsNotFoundError(err) to wait on watch events as intended.
			if !state.IsNotFoundError(err) {

Comment on lines +143 to +147
if !state.IsNotFoundError(err) {
require.NoError(err)
}

require.NoError(err)
asserter.NoError(err)
Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

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

This call will also catch NotFound errors (since you no longer continue), leading to immediate failures rather than waiting for the resource creation event. Consider guarding this call so it only runs when the resource is actually found.

Suggested change
if !state.IsNotFoundError(err) {
require.NoError(err)
}
require.NoError(err)
asserter.NoError(err)
if state.IsNotFoundError(err) {
// Skip NotFound errors as they are expected during resource creation
continue
} else {
require.NoError(err)
asserter.NoError(err)
}

Copilot uses AI. Check for mistakes.

asserter := assert.New(&aggregator)

res, err := safe.StateGet[R](ctx, st, resource.NewMetadata(namespace, rds.Type, id, resource.VersionUndefined))
Copy link
Member

Choose a reason for hiding this comment

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

we could even avoid Get completely and rely just on watch events, but I think it's fine as it is

Copy link
Member

Choose a reason for hiding this comment

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

and btw is not a busy loop, as it runs only on watch events anyways

Copy link
Member

Choose a reason for hiding this comment

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

scratch that, I see continue now

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep

@github-project-automation github-project-automation bot moved this from In Review to Approved in Planning Jul 9, 2025
@utkuozdemir
Copy link
Member Author

/m

@talos-bot talos-bot merged commit ccce7a8 into cosi-project:main Jul 9, 2025
14 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in Planning Jul 9, 2025
@utkuozdemir utkuozdemir deleted the fix/rtestutils-assertion branch July 9, 2025 10:07
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