diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index 11cd3b8dcbaa..90c870c0df98 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -29,7 +29,6 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/tools/record" - clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1" workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" karmadafake "github.com/karmada-io/karmada/pkg/generated/clientset/versioned/fake" "github.com/karmada-io/karmada/pkg/util" @@ -162,78 +161,6 @@ func TestCreateScheduler(t *testing.T) { }) } } - -func TestReconcileEstimatorConnection(t *testing.T) { - dynamicClient := dynamicfake.NewSimpleDynamicClient(runtime.NewScheme()) - karmadaClient := karmadafake.NewSimpleClientset() - kubeClient := fake.NewSimpleClientset() - scheduler, err := NewScheduler(dynamicClient, karmadaClient, kubeClient, WithEnableSchedulerEstimator(true)) - if err != nil { - t.Fatalf("Failed to create scheduler: %v", err) - } - - clusterName := "test-cluster" - cluster := &clusterv1alpha1.Cluster{ - ObjectMeta: metav1.ObjectMeta{Name: clusterName}, - Spec: clusterv1alpha1.ClusterSpec{SyncMode: clusterv1alpha1.Pull}, - } - _, err = karmadaClient.ClusterV1alpha1().Clusters().Create(context.TODO(), cluster, metav1.CreateOptions{}) - if err != nil { - t.Fatalf("Failed to create cluster: %v", err) - } - - tests := []struct { - name string - key util.QueueKey - disableSchedulerEstimatorInPullMode bool - expectedError bool - expectEstablishConnection bool - }{ - { - name: "Invalid key", - key: 123, - expectedError: true, - }, - { - name: "Cluster not found", - key: "non-existent-cluster", - expectedError: false, - }, - { - name: "Cluster in pull mode, estimator disabled", - key: clusterName, - disableSchedulerEstimatorInPullMode: true, - expectedError: false, - expectEstablishConnection: false, - }, - { - name: "Cluster in pull mode, estimator enabled", - key: clusterName, - disableSchedulerEstimatorInPullMode: false, - expectedError: false, - expectEstablishConnection: true, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - scheduler.disableSchedulerEstimatorInPullMode = tt.disableSchedulerEstimatorInPullMode - - err := scheduler.reconcileEstimatorConnection(tt.key) - if (err != nil) != tt.expectedError { - t.Errorf("reconcileEstimatorConnection() error = %v, expectedError %v", err, tt.expectedError) - } - - // We can't directly assert whether EstablishConnection is called. - // Instead, we'll check for conditions around its invocation. - // If EstablishConnection should be called, the error should be nil, and no early returns should have occurred. - if tt.expectEstablishConnection && err != nil { - t.Errorf("Expected EstablishConnection to be called, but got error: %v", err) - } - }) - } -} - func Test_patchBindingStatusCondition(t *testing.T) { oneHourBefore := time.Now().Add(-1 * time.Hour).Round(time.Second) oneHourAfter := time.Now().Add(1 * time.Hour).Round(time.Second)