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

Deflake cpumanager checkpoint unit tests #94541

Merged
merged 1 commit into from Sep 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 28 additions & 2 deletions pkg/kubelet/cm/cpumanager/state/state_checkpoint_test.go
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package state

import (
"io/ioutil"
"os"
"reflect"
"strings"
Expand All @@ -30,8 +31,6 @@ import (

const testingCheckpoint = "cpumanager_checkpoint_test"

var testingDir = os.TempDir()

func TestCheckpointStateRestore(t *testing.T) {
testCases := []struct {
description string
Expand Down Expand Up @@ -200,6 +199,12 @@ func TestCheckpointStateRestore(t *testing.T) {
},
}

// create temp dir
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(testingDir)
// create checkpoint manager for testing
cpm, err := checkpointmanager.NewCheckpointManager(testingDir)
if err != nil {
Expand Down Expand Up @@ -258,6 +263,13 @@ func TestCheckpointStateStore(t *testing.T) {
},
}

// create temp dir
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(testingDir)

cpm, err := checkpointmanager.NewCheckpointManager(testingDir)
if err != nil {
t.Fatalf("could not create testing checkpoint manager: %v", err)
Expand Down Expand Up @@ -324,6 +336,13 @@ func TestCheckpointStateHelpers(t *testing.T) {
},
}

// create temp dir
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(testingDir)

cpm, err := checkpointmanager.NewCheckpointManager(testingDir)
if err != nil {
t.Fatalf("could not create testing checkpoint manager: %v", err)
Expand Down Expand Up @@ -376,6 +395,13 @@ func TestCheckpointStateClear(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
// create temp dir
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(testingDir)

state, err := NewCheckpointState(testingDir, testingCheckpoint, "none", nil)
if err != nil {
t.Fatalf("could not create testing checkpointState instance: %v", err)
Expand Down