Skip to content
Open
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
1 change: 0 additions & 1 deletion pkg/ddc/jindo/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func (e *JindoEngine) syncMetadataInternal() (err error) {
e.Log.Error(err, "LoadMetadata failed when syncing metadata", "name", e.name, "namespace", e.namespace)
result.Err = err
result.Done = false
resultChan <- result
return
}*/
result.Done = true
Expand Down
1 change: 0 additions & 1 deletion pkg/ddc/jindocache/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func (e *JindoCacheEngine) syncMetadataInternal() (err error) {
if closed := base.SafeSend(resultChan, result); closed {
e.Log.Info("Recover from sending result to a closed channel", "result", result)
}
resultChan <- result
}(e.MetadataSyncDoneCh)
}
return
Expand Down
15 changes: 15 additions & 0 deletions pkg/ddc/jindocache/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
"github.com/fluid-cloudnative/fluid/pkg/utils/testutil"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -348,3 +349,17 @@ func TestSyncMetadataInternal(t *testing.T) {
}
}
}

func TestSyncMetadataInternalChannelLifecycle(t *testing.T) {
client := fake.NewFakeClientWithScheme(testScheme, &datav1alpha1.Dataset{
ObjectMeta: metav1.ObjectMeta{Name: "spark", Namespace: "fluid"},
})
engine := &JindoCacheEngine{
name: "spark", namespace: "fluid", Client: client, Log: fake.NullLogger(), runtime: &datav1alpha1.JindoRuntime{},
}
if err := testutil.VerifyMetadataSyncChannelClosedOnce(engine.syncMetadataInternal, func() <-chan base.MetadataSyncResult {
return engine.MetadataSyncDoneCh
}); err != nil {
t.Fatal(err)
}
}
1 change: 0 additions & 1 deletion pkg/ddc/jindofsx/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func (e *JindoFSxEngine) syncMetadataInternal() (err error) {
if closed := base.SafeSend(resultChan, result); closed {
e.Log.Info("Recover from sending result to a closed channel", "result", result)
}
resultChan <- result
}(e.MetadataSyncDoneCh)
}
return
Expand Down
15 changes: 15 additions & 0 deletions pkg/ddc/jindofsx/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
"github.com/fluid-cloudnative/fluid/pkg/utils/testutil"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -348,3 +349,17 @@ func TestSyncMetadataInternal(t *testing.T) {
}
}
}

func TestSyncMetadataInternalChannelLifecycle(t *testing.T) {
client := fake.NewFakeClientWithScheme(testScheme, &datav1alpha1.Dataset{
ObjectMeta: metav1.ObjectMeta{Name: "spark", Namespace: "fluid"},
})
engine := &JindoFSxEngine{
name: "spark", namespace: "fluid", Client: client, Log: fake.NullLogger(), runtime: &datav1alpha1.JindoRuntime{},
}
if err := testutil.VerifyMetadataSyncChannelClosedOnce(engine.syncMetadataInternal, func() <-chan base.MetadataSyncResult {
return engine.MetadataSyncDoneCh
}); err != nil {
t.Fatal(err)
}
}
56 changes: 56 additions & 0 deletions pkg/utils/testutil/metadata_sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2026 The Fluid Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package testutil

import (
"errors"
"fmt"
"time"
)

// VerifyMetadataSyncChannelClosedOnce verifies that an async metadata sync initializes
// its result channel on the first call, receives one result and clears it on a follow-up
// call, and closes the channel cleanly without blocking on a duplicate send.
func VerifyMetadataSyncChannelClosedOnce[T any](syncFn func() error, getCh func() <-chan T) error {
if err := syncFn(); err != nil {
return fmt.Errorf("first sync call failed: %w", err)
}
ch := getCh()
if ch == nil {
return errors.New("expected metadata sync channel to be initialized")
}

deadline := time.Now().Add(5 * time.Second)
for getCh() != nil {
if err := syncFn(); err != nil {
return fmt.Errorf("follow-up sync call failed: %w", err)
}
if time.Now().After(deadline) {
return errors.New("timed out waiting for metadata sync channel to be cleared")
}
}

select {
case _, ok := <-ch:
if ok {
return errors.New("unexpected second value sent to metadata sync channel")
}
return nil
case <-time.After(time.Second):
return errors.New("timed out waiting for metadata sync channel to close; goroutine likely blocked on duplicate send")
}
}