Skip to content

Commit

Permalink
delete unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Oded Viner <[email protected]>
  • Loading branch information
OdedViner committed Feb 20, 2025
1 parent bf37295 commit 97434e6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 73 deletions.
1 change: 1 addition & 0 deletions internal/controller/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ func (r *DRPlacementControlReconciler) getStatusCheckDelay(
if remaining < 0 {
return 0
}

return remaining
}

Expand Down
73 changes: 0 additions & 73 deletions internal/controller/drplacementcontrol_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"runtime"
"strings"
"testing"
"time"

volrep "github.com/csi-addons/kubernetes-csi-addons/api/replication.storage/v1alpha1"
Expand Down Expand Up @@ -3193,75 +3192,3 @@ func forceCleanupClusterAfterAErrorTest() error {

return nil
}

// TestGetStatusCheckDelay verifies the behavior of getStatusCheckDelay across different scenarios.
func TestGetStatusCheckDelay(t *testing.T) {
tests := []struct {
name string
getTimes func() (before, after metav1.Time)
expectedDelay func(before metav1.Time) time.Duration
tolerance time.Duration
}{
{
name: "processing time changed returns full delay",
getTimes: func() (metav1.Time, metav1.Time) {
now := time.Now()
// Simulate processing time change by having after != before.
return metav1.NewTime(now), metav1.NewTime(now.Add(1 * time.Millisecond))
},
// When processing times differ, we expect the full StatusCheckDelay.
expectedDelay: func(before metav1.Time) time.Duration {
return controllers.StatusCheckDelay
},
tolerance: 0,
},
{
name: "remaining time returns nearly full delay",
getTimes: func() (metav1.Time, metav1.Time) {
now := time.Now()
// Processing times are equal; no status update occurred.
tBefore := metav1.NewTime(now)
return tBefore, tBefore
},
// Expected delay is the remaining time until beforeProcessing+StatusCheckDelay.
expectedDelay: func(before metav1.Time) time.Duration {
return time.Until(before.Add(controllers.StatusCheckDelay))
},
// Allow a small tolerance since time passes between calls.
tolerance: 10 * time.Millisecond,
},
{
name: "elapsed scheduled time returns 0",
getTimes: func() (metav1.Time, metav1.Time) {
// Set beforeProcessing in the past such that before+StatusCheckDelay is already elapsed.
past := time.Now().Add(-controllers.StatusCheckDelay - 1*time.Second)
tPast := metav1.NewTime(past)
return tPast, tPast
},
// If the scheduled time has passed, we expect a delay of 0.
expectedDelay: func(before metav1.Time) time.Duration {
return 0
},
tolerance: 0,
},
}

// Create an instance of the reconciler.
reconciler := &controllers.DRPlacementControlReconciler{}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
before, after := tc.getTimes()
// Calculate the expected delay using the provided function.
expected := tc.expectedDelay(before)
// Get the actual delay from the reconciler.
actual := reconciler.GetStatusCheckDelay(before, after)

// Check that the difference between expected and actual is within the tolerance.
diff := actual - expected
if diff < -tc.tolerance || diff > tc.tolerance {
t.Errorf("Test %q: expected delay ~%v (±%v), got %v", tc.name, expected, tc.tolerance, actual)
}
})
}
}

0 comments on commit 97434e6

Please sign in to comment.