Skip to content
Merged
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
3 changes: 2 additions & 1 deletion internal/health-checker/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ func (hcm *healthCheckManager) startStatChecker(volumeID, path string, shared bo
// are key'd by theit volumeID+path.
func (hcm *healthCheckManager) startChecker(cc ConditionChecker, volumeID, path string, shared bool) error {
key := volumeID
if shared {
if !shared {
// if it is non-shared checker, try to use the path as well.
key = fallbackKey(volumeID, path)
}

Expand Down
56 changes: 54 additions & 2 deletions internal/health-checker/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ package healthchecker

import (
"testing"

"github.com/stretchr/testify/require"
)

const volumeID = "fake-volume-id"

func TestManager(t *testing.T) {
t.Parallel()

volumeID := "fake-volume-id"
volumePath := t.TempDir()
mgr := NewHealthCheckManager()

Expand Down Expand Up @@ -52,7 +55,6 @@ func TestManager(t *testing.T) {
func TestSharedChecker(t *testing.T) {
t.Parallel()

volumeID := "fake-volume-id"
volumePath := t.TempDir()
mgr := NewHealthCheckManager()

Expand Down Expand Up @@ -83,3 +85,53 @@ func TestSharedChecker(t *testing.T) {
t.Log("stop the checker")
mgr.StopSharedChecker(volumeID)
}

func TestTwoNonSharedChecker(t *testing.T) {
t.Parallel()

// create two different paths for same volumeID
// to test if the checkers are independent
firstVolumePath := t.TempDir()
secondVolumePath := t.TempDir()
mgr := NewHealthCheckManager()

t.Log("start the first checker")
err := mgr.StartChecker(volumeID, firstVolumePath, StatCheckerType)
if err != nil {
t.Fatalf("ConditionChecker could not get started: %v", err)
}

t.Log("check health for first path, should be healthy")
healthy, msg := mgr.IsHealthy(volumeID, firstVolumePath)
if !healthy || err != nil {
t.Errorf("volume is unhealthy: %s", msg)
}

t.Log("check health for second path, should error out since checker is not started")
_, msg = mgr.IsHealthy(volumeID, secondVolumePath)
require.ErrorContains(t, msg, "no ConditionChecker for volume-id")

t.Log("start the second checker")
err = mgr.StartChecker(volumeID, secondVolumePath, StatCheckerType)
if err != nil {
t.Fatalf("ConditionChecker could not get started: %v", err)
}

t.Log("check health, should be healthy")
healthy, msg = mgr.IsHealthy(volumeID, secondVolumePath)
if !healthy || err != nil {
t.Errorf("volume is unhealthy: %s", msg)
}

t.Log("stop the first checker")
mgr.StopChecker(volumeID, firstVolumePath)

t.Log("check health of second path, should still be healthy")
healthy, msg = mgr.IsHealthy(volumeID, secondVolumePath)
if !healthy || err != nil {
t.Errorf("volume is unhealthy: %s", msg)
}

t.Log("stop the second checker")
mgr.StopChecker(volumeID, secondVolumePath)
}