Skip to content

Commit

Permalink
Parallelize tests to allow us to reenable testing in pkg/...
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Klues <[email protected]>
  • Loading branch information
klueska committed Apr 23, 2024
1 parent f821741 commit ca399c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ check-vendor: vendor

COVERAGE_FILE := coverage.out
test: build cmds
go test -coverprofile=$(COVERAGE_FILE) $(MODULE)/cmd/... $(MODULE)/internal/... $(MODULE)/api/...
go test -v -coverprofile=$(COVERAGE_FILE) $(MODULE)/cmd/... $(MODULE)/internal/... $(MODULE)/api/... $(MODULE)/pkg/...

coverage: test
cat $(COVERAGE_FILE) | grep -v "_mock.go" > $(COVERAGE_FILE).no-mocks
Expand Down
31 changes: 21 additions & 10 deletions pkg/mig/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@ func EnableMigMode(manager Manager, gpu int) (nvml.Return, nvml.Return) {
}

func TestGetSetMigConfig(t *testing.T) {
nvmlLib := dgxa100.New()
manager := NewMockLunaServerMigConfigManager()

numGPUs, ret := nvmlLib.DeviceGetCount()
require.NotNil(t, ret, "Unexpected nil return from DeviceGetCount")
require.Equal(t, ret, nvml.SUCCESS, "Unexpected return value from DeviceGetCount")

types.SetMockNVdevlib()
mcg := NewA100_SXM4_40GB_MigConfigGroup()

type testCase struct {
Expand All @@ -69,8 +63,18 @@ func TestGetSetMigConfig(t *testing.T) {
return testCases
}()

for _, tc := range testCases {
for i := range testCases {
tc := testCases[i] // to allow us to run parallelly
t.Run(tc.description, func(t *testing.T) {
t.Parallel()

nvmlLib := dgxa100.New()
manager := NewMockLunaServerMigConfigManager()

numGPUs, ret := nvmlLib.DeviceGetCount()
require.NotNil(t, ret, "Unexpected nil return from DeviceGetCount")
require.Equal(t, ret, nvml.SUCCESS, "Unexpected return value from DeviceGetCount")

for i := 0; i < numGPUs; i++ {
r1, r2 := EnableMigMode(manager, i)
require.Equal(t, nvml.SUCCESS, r1)
Expand All @@ -88,6 +92,7 @@ func TestGetSetMigConfig(t *testing.T) {
}

func TestClearMigConfig(t *testing.T) {
types.SetMockNVdevlib()
mcg := NewA100_SXM4_40GB_MigConfigGroup()

type testCase struct {
Expand All @@ -106,8 +111,11 @@ func TestClearMigConfig(t *testing.T) {
return testCases
}()

for _, tc := range testCases {
for i := range testCases {
tc := testCases[i] // to allow us to run parallelly
t.Run(tc.description, func(t *testing.T) {
t.Parallel()

manager := NewMockLunaServerMigConfigManager()

r1, r2 := EnableMigMode(manager, 0)
Expand Down Expand Up @@ -173,8 +181,11 @@ func TestIteratePermutationsUntilSuccess(t *testing.T) {
return testCases
}()

for _, tc := range testCases {
for i := range testCases {
tc := testCases[i] // to allow us to run parallelly
t.Run(tc.description, func(t *testing.T) {
t.Parallel()

iteration := 0
err := iteratePermutationsUntilSuccess(tc.config, func(perm []*types.MigProfile) error {
iteration++
Expand Down
4 changes: 3 additions & 1 deletion pkg/mig/config/known_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ func TestValidConfiguration(t *testing.T) {
types.SetMockNVdevlib()
configs := GetKnownMigConfigGroups()

for _, tc := range testCases {
for i := range testCases {
tc := testCases[i] // to allow us to run parallelly
t.Run(tc.description, func(t *testing.T) {
t.Parallel()
err := configs[tc.gpu].AssertValidConfiguration(tc.config)
if tc.valid {
require.Nil(t, err)
Expand Down
18 changes: 11 additions & 7 deletions pkg/mig/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ func newMockMigStateManagerOnLunaServer() *migStateManager {
}

func TestFetchRestore(t *testing.T) {
manager := newMockMigStateManagerOnLunaServer()

numGPUs, ret := manager.nvml.DeviceGetCount()
require.NotNil(t, ret, "Unexpected nil return from DeviceGetCount")
require.Equal(t, ret, nvml.SUCCESS, "Unexpected return value from DeviceGetCount")

types.SetMockNVdevlib()
mcg := config.NewA100_SXM4_40GB_MigConfigGroup()

type testCase struct {
Expand Down Expand Up @@ -73,8 +68,17 @@ func TestFetchRestore(t *testing.T) {
return testCases
}()

for _, tc := range testCases {
for i := range testCases {
tc := testCases[i] // to allow us to run parallelly
t.Run(tc.description, func(t *testing.T) {
t.Parallel()

manager := newMockMigStateManagerOnLunaServer()

numGPUs, ret := manager.nvml.DeviceGetCount()
require.NotNil(t, ret, "Unexpected nil return from DeviceGetCount")
require.Equal(t, ret, nvml.SUCCESS, "Unexpected return value from DeviceGetCount")

for i := 0; i < numGPUs; i++ {
err := manager.mode.SetMigMode(i, tc.mode)
require.Nil(t, err)
Expand Down

0 comments on commit ca399c4

Please sign in to comment.