Skip to content
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 resource slice self healing unit test #256

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
branches:
- main
workflow_dispatch:
schedule:
- cron: 0 0 * * *

jobs:
test:
Expand Down
12 changes: 11 additions & 1 deletion internal/controllers/selfhealing/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ func TestRequeueForNotEligibleResynthesis(t *testing.T) {
comp.Status.PendingResynthesis = ptr.To(metav1.Now())
return mgr.GetClient().Status().Update(ctx, comp)
})
require.NoError(t, err)

res, err = s.Reconcile(ctx, req)
require.NoError(t, err)
// Should re-quque after grace period time, due to (gracePeriod - time.Since(synthesized)) < 0
Expand All @@ -332,6 +334,7 @@ func TestRequeueForNotEligibleResynthesis(t *testing.T) {

// Update composition with synthesize time for re-queue
synthesized = time.Now().Add(-time.Minute)
oldResourceVersion := comp.GetResourceVersion()
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
err := mgr.GetClient().Get(ctx, client.ObjectKeyFromObject(comp), comp)
if err != nil {
Expand All @@ -341,13 +344,20 @@ func TestRequeueForNotEligibleResynthesis(t *testing.T) {
comp.Status.PendingResynthesis = ptr.To(metav1.Now())
return mgr.GetClient().Status().Update(ctx, comp)
})
require.NoError(t, err)

// Ensure the composition is updated completely before reconciliation
testutil.Eventually(t, func() bool {
err := mgr.GetClient().Get(ctx, client.ObjectKeyFromObject(comp), comp)
return err == nil && comp.GetResourceVersion() != oldResourceVersion
})

res, err = s.Reconcile(ctx, req)
require.NoError(t, err)
assert.True(t, res.Requeue)
assert.True(t, res.RequeueAfter.Seconds() > 0)
// Re-queue after (gracePeriod - time.Since(synthesized))
assert.True(t, s.selfHealingGracePeriod > res.RequeueAfter)

}

func TestNotEligibleForResynthesis(t *testing.T) {
Expand Down
Loading