mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #104959 from calvin0327/issue-test-dataRace
fix the test issue of node shutdown manager
This commit is contained in:
commit
7c71e06cd1
@ -39,6 +39,9 @@ import (
|
||||
testingclock "k8s.io/utils/clock/testing"
|
||||
)
|
||||
|
||||
// lock is to prevent systemDbus from being modified in the case of concurrency.
|
||||
var lock sync.Mutex
|
||||
|
||||
type fakeDbus struct {
|
||||
currentInhibitDelay time.Duration
|
||||
overrideSystemInhibitDelay time.Duration
|
||||
@ -226,6 +229,8 @@ func TestManager(t *testing.T) {
|
||||
|
||||
fakeShutdownChan := make(chan bool)
|
||||
fakeDbus := &fakeDbus{currentInhibitDelay: tc.systemInhibitDelay, shutdownChan: fakeShutdownChan, overrideSystemInhibitDelay: tc.overrideSystemInhibitDelay}
|
||||
|
||||
lock.Lock()
|
||||
systemDbus = func() (dbusInhibiter, error) {
|
||||
return fakeDbus, nil
|
||||
}
|
||||
@ -238,6 +243,8 @@ func TestManager(t *testing.T) {
|
||||
manager.clock = testingclock.NewFakeClock(time.Now())
|
||||
|
||||
err := manager.Start()
|
||||
lock.Unlock()
|
||||
|
||||
if tc.expectedError != nil {
|
||||
if !strings.Contains(err.Error(), tc.expectedError.Error()) {
|
||||
t.Errorf("unexpected error message. Got: %s want %s", err.Error(), tc.expectedError.Error())
|
||||
@ -341,6 +348,7 @@ func TestRestart(t *testing.T) {
|
||||
var shutdownChanMut sync.Mutex
|
||||
var connChan = make(chan struct{}, 1)
|
||||
|
||||
lock.Lock()
|
||||
systemDbus = func() (dbusInhibiter, error) {
|
||||
defer func() {
|
||||
connChan <- struct{}{}
|
||||
@ -357,6 +365,8 @@ func TestRestart(t *testing.T) {
|
||||
nodeRef := &v1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""}
|
||||
manager, _ := NewManager(fakeRecorder, nodeRef, activePodsFunc, killPodsFunc, syncNodeStatus, shutdownGracePeriodRequested, shutdownGracePeriodCriticalPods)
|
||||
err := manager.Start()
|
||||
lock.Unlock()
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user