@@ -2533,7 +2533,7 @@ func TestSelfHealExponentialBackoff(t *testing.T) {
2533
2533
ctrl .selfHealBackOff = & wait.Backoff {
2534
2534
Factor : 3 ,
2535
2535
Duration : 2 * time .Second ,
2536
- Cap : 5 * time .Minute ,
2536
+ Cap : 2 * time .Minute ,
2537
2537
}
2538
2538
2539
2539
app := & v1alpha1.Application {
@@ -2548,38 +2548,95 @@ func TestSelfHealExponentialBackoff(t *testing.T) {
2548
2548
2549
2549
testCases := []struct {
2550
2550
attempts int64
2551
+ expectedAttempts int64
2551
2552
finishedAt * metav1.Time
2552
2553
expectedDuration time.Duration
2553
2554
shouldSelfHeal bool
2555
+ alreadyAttempted bool
2556
+ syncStatus v1alpha1.SyncStatusCode
2554
2557
}{{
2555
2558
attempts : 0 ,
2556
2559
finishedAt : ptr .To (metav1 .Now ()),
2557
2560
expectedDuration : 0 ,
2558
2561
shouldSelfHeal : true ,
2562
+ alreadyAttempted : true ,
2563
+ expectedAttempts : 0 ,
2564
+ syncStatus : v1alpha1 .SyncStatusCodeOutOfSync ,
2559
2565
}, {
2560
2566
attempts : 1 ,
2561
2567
finishedAt : ptr .To (metav1 .Now ()),
2562
2568
expectedDuration : 2 * time .Second ,
2563
2569
shouldSelfHeal : false ,
2570
+ alreadyAttempted : true ,
2571
+ expectedAttempts : 1 ,
2572
+ syncStatus : v1alpha1 .SyncStatusCodeOutOfSync ,
2564
2573
}, {
2565
2574
attempts : 2 ,
2566
2575
finishedAt : ptr .To (metav1 .Now ()),
2567
2576
expectedDuration : 6 * time .Second ,
2568
2577
shouldSelfHeal : false ,
2578
+ alreadyAttempted : true ,
2579
+ expectedAttempts : 2 ,
2580
+ syncStatus : v1alpha1 .SyncStatusCodeOutOfSync ,
2569
2581
}, {
2570
2582
attempts : 3 ,
2571
2583
finishedAt : nil ,
2572
2584
expectedDuration : 18 * time .Second ,
2573
2585
shouldSelfHeal : false ,
2586
+ alreadyAttempted : true ,
2587
+ expectedAttempts : 3 ,
2588
+ syncStatus : v1alpha1 .SyncStatusCodeOutOfSync ,
2589
+ }, {
2590
+ attempts : 4 ,
2591
+ finishedAt : nil ,
2592
+ expectedDuration : 54 * time .Second ,
2593
+ shouldSelfHeal : false ,
2594
+ alreadyAttempted : true ,
2595
+ expectedAttempts : 4 ,
2596
+ syncStatus : v1alpha1 .SyncStatusCodeOutOfSync ,
2597
+ }, {
2598
+ attempts : 5 ,
2599
+ finishedAt : nil ,
2600
+ expectedDuration : 120 * time .Second ,
2601
+ shouldSelfHeal : false ,
2602
+ alreadyAttempted : true ,
2603
+ expectedAttempts : 5 ,
2604
+ syncStatus : v1alpha1 .SyncStatusCodeOutOfSync ,
2605
+ }, {
2606
+ attempts : 6 ,
2607
+ finishedAt : nil ,
2608
+ expectedDuration : 120 * time .Second ,
2609
+ shouldSelfHeal : false ,
2610
+ alreadyAttempted : true ,
2611
+ expectedAttempts : 6 ,
2612
+ syncStatus : v1alpha1 .SyncStatusCodeOutOfSync ,
2613
+ }, {
2614
+ attempts : 6 ,
2615
+ finishedAt : nil ,
2616
+ expectedDuration : 0 ,
2617
+ shouldSelfHeal : true ,
2618
+ alreadyAttempted : false ,
2619
+ expectedAttempts : 0 ,
2620
+ syncStatus : v1alpha1 .SyncStatusCodeOutOfSync ,
2621
+ }, {
2622
+ attempts : 6 ,
2623
+ finishedAt : nil ,
2624
+ expectedDuration : 0 ,
2625
+ shouldSelfHeal : true ,
2626
+ alreadyAttempted : true ,
2627
+ expectedAttempts : 0 ,
2628
+ syncStatus : v1alpha1 .SyncStatusCodeSynced ,
2574
2629
}}
2575
2630
2576
2631
for i := range testCases {
2577
2632
tc := testCases [i ]
2578
2633
t .Run (fmt .Sprintf ("test case %d" , i ), func (t * testing.T ) {
2579
2634
app .Status .OperationState .Operation .Sync .SelfHealAttemptsCount = tc .attempts
2580
2635
app .Status .OperationState .FinishedAt = tc .finishedAt
2581
- ok , duration := ctrl .shouldSelfHeal (app )
2636
+ app .Status .Sync .Status = tc .syncStatus
2637
+ ok , duration := ctrl .shouldSelfHeal (app , tc .alreadyAttempted )
2582
2638
require .Equal (t , ok , tc .shouldSelfHeal )
2639
+ require .Equal (t , tc .expectedAttempts , app .Status .OperationState .Operation .Sync .SelfHealAttemptsCount )
2583
2640
assertDurationAround (t , tc .expectedDuration , duration )
2584
2641
})
2585
2642
}
0 commit comments