-
Notifications
You must be signed in to change notification settings - Fork 15
fix: fix resource assertion logic and its logging #618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix resource assertion logic and its logging #618
Conversation
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>
There was a problem hiding this 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
StateGetloops with watch-based blocking - Remove per-iteration NotFound logging and deduplicate reports
- Fix typo
lastReporedOk→lastReportedOk
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 tocontinuethe loop whenstate.IsNotFoundError(err)to wait on watch events as intended.
if !state.IsNotFoundError(err) {
| if !state.IsNotFoundError(err) { | ||
| require.NoError(err) | ||
| } | ||
|
|
||
| require.NoError(err) | ||
| asserter.NoError(err) |
Copilot
AI
Jul 8, 2025
There was a problem hiding this comment.
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.
| 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) | |
| } |
|
|
||
| asserter := assert.New(&aggregator) | ||
|
|
||
| res, err := safe.StateGet[R](ctx, st, resource.NewMetadata(namespace, rds.Type, id, resource.VersionUndefined)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep
|
/m |
Fix two things in the resource asserters:
We were doing a busy
state.Getloop 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 onwatchevents).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.