Deflake cpumanager checkpoint unit tests

This commit is contained in:
Jordan Liggitt 2020-09-04 15:06:04 -04:00
parent a23cf7077e
commit 7268b1d557

View File

@ -17,6 +17,7 @@ limitations under the License.
package state
import (
"io/ioutil"
"os"
"reflect"
"strings"
@ -30,8 +31,6 @@ import (
const testingCheckpoint = "cpumanager_checkpoint_test"
var testingDir = os.TempDir()
func TestCheckpointStateRestore(t *testing.T) {
testCases := []struct {
description string
@ -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 {
@ -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)
@ -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)
@ -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)