mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +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"
|
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 {
|
type fakeDbus struct {
|
||||||
currentInhibitDelay time.Duration
|
currentInhibitDelay time.Duration
|
||||||
overrideSystemInhibitDelay time.Duration
|
overrideSystemInhibitDelay time.Duration
|
||||||
@ -226,6 +229,8 @@ func TestManager(t *testing.T) {
|
|||||||
|
|
||||||
fakeShutdownChan := make(chan bool)
|
fakeShutdownChan := make(chan bool)
|
||||||
fakeDbus := &fakeDbus{currentInhibitDelay: tc.systemInhibitDelay, shutdownChan: fakeShutdownChan, overrideSystemInhibitDelay: tc.overrideSystemInhibitDelay}
|
fakeDbus := &fakeDbus{currentInhibitDelay: tc.systemInhibitDelay, shutdownChan: fakeShutdownChan, overrideSystemInhibitDelay: tc.overrideSystemInhibitDelay}
|
||||||
|
|
||||||
|
lock.Lock()
|
||||||
systemDbus = func() (dbusInhibiter, error) {
|
systemDbus = func() (dbusInhibiter, error) {
|
||||||
return fakeDbus, nil
|
return fakeDbus, nil
|
||||||
}
|
}
|
||||||
@ -238,6 +243,8 @@ func TestManager(t *testing.T) {
|
|||||||
manager.clock = testingclock.NewFakeClock(time.Now())
|
manager.clock = testingclock.NewFakeClock(time.Now())
|
||||||
|
|
||||||
err := manager.Start()
|
err := manager.Start()
|
||||||
|
lock.Unlock()
|
||||||
|
|
||||||
if tc.expectedError != nil {
|
if tc.expectedError != nil {
|
||||||
if !strings.Contains(err.Error(), tc.expectedError.Error()) {
|
if !strings.Contains(err.Error(), tc.expectedError.Error()) {
|
||||||
t.Errorf("unexpected error message. Got: %s want %s", 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 shutdownChanMut sync.Mutex
|
||||||
var connChan = make(chan struct{}, 1)
|
var connChan = make(chan struct{}, 1)
|
||||||
|
|
||||||
|
lock.Lock()
|
||||||
systemDbus = func() (dbusInhibiter, error) {
|
systemDbus = func() (dbusInhibiter, error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
connChan <- struct{}{}
|
connChan <- struct{}{}
|
||||||
@ -357,6 +365,8 @@ func TestRestart(t *testing.T) {
|
|||||||
nodeRef := &v1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""}
|
nodeRef := &v1.ObjectReference{Kind: "Node", Name: "test", UID: types.UID("test"), Namespace: ""}
|
||||||
manager, _ := NewManager(fakeRecorder, nodeRef, activePodsFunc, killPodsFunc, syncNodeStatus, shutdownGracePeriodRequested, shutdownGracePeriodCriticalPods)
|
manager, _ := NewManager(fakeRecorder, nodeRef, activePodsFunc, killPodsFunc, syncNodeStatus, shutdownGracePeriodRequested, shutdownGracePeriodCriticalPods)
|
||||||
err := manager.Start()
|
err := manager.Start()
|
||||||
|
lock.Unlock()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user