Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelize tests to allow us to reenable testing in pkg/... #63

Merged
merged 1 commit into from
Apr 24, 2024
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
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