mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #103291 from wzshiming/fix/nodeshutdown-restart
Fix Data Race in nodeshutdown restart
This commit is contained in:
commit
a6c2cd7d18
@ -21,6 +21,7 @@ package nodeshutdown
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -329,15 +330,18 @@ func TestRestart(t *testing.T) {
|
|||||||
syncNodeStatus := func() {}
|
syncNodeStatus := func() {}
|
||||||
|
|
||||||
var shutdownChan chan bool
|
var shutdownChan chan bool
|
||||||
|
var shutdownChanMut sync.Mutex
|
||||||
var connChan = make(chan struct{}, 1)
|
var connChan = make(chan struct{}, 1)
|
||||||
|
|
||||||
systemDbus = func() (dbusInhibiter, error) {
|
systemDbus = func() (dbusInhibiter, error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
connChan <- struct{}{}
|
connChan <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
ch := make(chan bool)
|
||||||
shutdownChan = make(chan bool)
|
shutdownChanMut.Lock()
|
||||||
dbus := &fakeDbus{currentInhibitDelay: systemInhibitDelay, shutdownChan: shutdownChan, overrideSystemInhibitDelay: overrideSystemInhibitDelay}
|
shutdownChan = ch
|
||||||
|
shutdownChanMut.Unlock()
|
||||||
|
dbus := &fakeDbus{currentInhibitDelay: systemInhibitDelay, shutdownChan: ch, overrideSystemInhibitDelay: overrideSystemInhibitDelay}
|
||||||
return dbus, nil
|
return dbus, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,14 +351,15 @@ func TestRestart(t *testing.T) {
|
|||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i != 5; i++ {
|
for i := 0; i != 3; i++ {
|
||||||
select {
|
select {
|
||||||
case <-time.After(dbusReconnectPeriod * 5):
|
case <-time.After(dbusReconnectPeriod * 5):
|
||||||
t.Fatal("wait dbus connect timeout")
|
t.Fatal("wait dbus connect timeout")
|
||||||
case <-connChan:
|
case <-connChan:
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
shutdownChanMut.Lock()
|
||||||
close(shutdownChan)
|
close(shutdownChan)
|
||||||
|
shutdownChanMut.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user