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
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ func IsUnhealthyAPIError(err error) bool {
case dcgm.DCGM_ST_NVML_ERROR,
dcgm.DCGM_ST_GPU_IS_LOST,
dcgm.DCGM_ST_RESET_REQUIRED,
dcgm.DCGM_ST_GPU_NOT_SUPPORTED,
dcgm.DCGM_ST_TIMEOUT,
dcgm.DCGM_ST_NVML_DRIVER_TIMEOUT:
dcgm.DCGM_ST_GPU_NOT_SUPPORTED:
return true
default:
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
package dcgm

import (
"fmt"
"testing"

dcgm "github.com/NVIDIA/go-dcgm/pkg/dcgm"
)

// Note: Tests for CheckSentinel() and CheckSentinelV2() require actual DCGM library
Expand Down Expand Up @@ -66,3 +69,28 @@ func TestSentinelType_String(t *testing.T) {
})
}
}

func TestIsUnhealthyAPIError(t *testing.T) {
tests := []struct {
name string
code int32
want bool
}{
{"nvml error is unhealthy", dcgm.DCGM_ST_NVML_ERROR, true},
{"gpu lost is unhealthy", dcgm.DCGM_ST_GPU_IS_LOST, true},
{"reset required is unhealthy", dcgm.DCGM_ST_RESET_REQUIRED, true},
{"gpu not supported is unhealthy", dcgm.DCGM_ST_GPU_NOT_SUPPORTED, true},
{"dcgm timeout is degraded", dcgm.DCGM_ST_TIMEOUT, false},
{"nvml driver timeout is degraded", dcgm.DCGM_ST_NVML_DRIVER_TIMEOUT, false},
{"stale data is not unhealthy", dcgm.DCGM_ST_STALE_DATA, false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := fmt.Errorf("dcgm request failed with error code %d", tt.code)
if got := IsUnhealthyAPIError(err); got != tt.want {
t.Errorf("IsUnhealthyAPIError() = %v, want %v", got, tt.want)
}
})
}
}
Loading