Skip to content

Commit 60c421b

Browse files
authored
Merge pull request kubernetes#94541 from liggitt/deflake-cpucheckpoint
Deflake cpumanager checkpoint unit tests
2 parents 0f466ba + 7268b1d commit 60c421b

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

pkg/kubelet/cm/cpumanager/state/state_checkpoint_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package state
1818

1919
import (
20+
"io/ioutil"
2021
"os"
2122
"reflect"
2223
"strings"
@@ -30,8 +31,6 @@ import (
3031

3132
const testingCheckpoint = "cpumanager_checkpoint_test"
3233

33-
var testingDir = os.TempDir()
34-
3534
func TestCheckpointStateRestore(t *testing.T) {
3635
testCases := []struct {
3736
description string
@@ -200,6 +199,12 @@ func TestCheckpointStateRestore(t *testing.T) {
200199
},
201200
}
202201

202+
// create temp dir
203+
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
204+
if err != nil {
205+
t.Fatal(err)
206+
}
207+
defer os.RemoveAll(testingDir)
203208
// create checkpoint manager for testing
204209
cpm, err := checkpointmanager.NewCheckpointManager(testingDir)
205210
if err != nil {
@@ -258,6 +263,13 @@ func TestCheckpointStateStore(t *testing.T) {
258263
},
259264
}
260265

266+
// create temp dir
267+
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
268+
if err != nil {
269+
t.Fatal(err)
270+
}
271+
defer os.RemoveAll(testingDir)
272+
261273
cpm, err := checkpointmanager.NewCheckpointManager(testingDir)
262274
if err != nil {
263275
t.Fatalf("could not create testing checkpoint manager: %v", err)
@@ -324,6 +336,13 @@ func TestCheckpointStateHelpers(t *testing.T) {
324336
},
325337
}
326338

339+
// create temp dir
340+
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
341+
if err != nil {
342+
t.Fatal(err)
343+
}
344+
defer os.RemoveAll(testingDir)
345+
327346
cpm, err := checkpointmanager.NewCheckpointManager(testingDir)
328347
if err != nil {
329348
t.Fatalf("could not create testing checkpoint manager: %v", err)
@@ -376,6 +395,13 @@ func TestCheckpointStateClear(t *testing.T) {
376395

377396
for _, tc := range testCases {
378397
t.Run(tc.description, func(t *testing.T) {
398+
// create temp dir
399+
testingDir, err := ioutil.TempDir("", "cpumanager_state_test")
400+
if err != nil {
401+
t.Fatal(err)
402+
}
403+
defer os.RemoveAll(testingDir)
404+
379405
state, err := NewCheckpointState(testingDir, testingCheckpoint, "none", nil)
380406
if err != nil {
381407
t.Fatalf("could not create testing checkpointState instance: %v", err)

0 commit comments

Comments
 (0)