From 42f6f909900093abdbef5e4fac64e351ab06c5d8 Mon Sep 17 00:00:00 2001 From: Santosh Date: Fri, 15 May 2026 13:01:19 +0530 Subject: [PATCH] osd: fix flaky TestAddRemoveNode failure User RaceFreeFakeWatcher isntead of FakeWatcher in TestAddRemoveNode function. The test runs c.Start() in a goroutine whch stops the watcher when done. If mockNodeOrchestrationCompeltion sends a watch ever after, that, FakeWatcher panics with "send on a closed channel". RaceFreeFakeWatcher safely ignores the sends on a stopped channel. Signed-off-by: Santosh (cherry picked from commit 6781d2e58d17db246b828b83681463328db5643d) --- pkg/operator/ceph/cluster/osd/osd_test.go | 4 ++-- pkg/operator/ceph/cluster/osd/status_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/operator/ceph/cluster/osd/osd_test.go b/pkg/operator/ceph/cluster/osd/osd_test.go index 52fd4ead0..e54113294 100644 --- a/pkg/operator/ceph/cluster/osd/osd_test.go +++ b/pkg/operator/ceph/cluster/osd/osd_test.go @@ -201,7 +201,7 @@ func TestAddRemoveNode(t *testing.T) { cmErr := createDiscoverConfigmap(nodeName, "rook-system", clientset) assert.Nil(t, cmErr) - statusMapWatcher := watch.NewFake() + statusMapWatcher := watch.NewRaceFreeFake() clientset.PrependWatchReactor("configmaps", k8stesting.DefaultWatchReactor(statusMapWatcher, nil)) clusterInfo := &cephclient.ClusterInfo{ @@ -361,7 +361,7 @@ func TestAddRemoveNode(t *testing.T) { c = New(context, clusterInfo, cephCluster.Spec, "myversion") // reset the orchestration status watcher - statusMapWatcher = watch.NewFake() + statusMapWatcher = watch.NewRaceFreeFake() clientset.PrependWatchReactor("configmaps", k8stesting.DefaultWatchReactor(statusMapWatcher, nil)) startErr = nil diff --git a/pkg/operator/ceph/cluster/osd/status_test.go b/pkg/operator/ceph/cluster/osd/status_test.go index 71a658b2c..060cd9273 100644 --- a/pkg/operator/ceph/cluster/osd/status_test.go +++ b/pkg/operator/ceph/cluster/osd/status_test.go @@ -67,7 +67,7 @@ func TestOrchestrationStatus(t *testing.T) { assert.Equal(t, status, *retrievedStatus) } -func mockNodeOrchestrationCompletion(c *Cluster, nodeName string, statusMapWatcher *watch.FakeWatcher) { +func mockNodeOrchestrationCompletion(c *Cluster, nodeName string, statusMapWatcher *watch.RaceFreeFakeWatcher) { ctx := context.TODO() // if no valid osd node, don't need to check its status, return immediately if len(c.spec.Storage.Nodes) == 0 {