Skip to content

Commit

Permalink
Fixed race condition test manager shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarsh348 committed Feb 18, 2022
1 parent 15fb945 commit eaee96e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pkg/kubelet/nodeshutdown/nodeshutdown_manager_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,23 @@ func Test_groupByPriority(t *testing.T) {
}
}

type buffer struct {
b bytes.Buffer
rw sync.RWMutex
}

func (b *buffer) String() string {
b.rw.RLock()
defer b.rw.RUnlock()
return b.b.String()
}

func (b *buffer) Write(p []byte) (n int, err error) {
b.rw.Lock()
defer b.rw.Unlock()
return b.b.Write(p)
}

func Test_managerImpl_processShutdownEvent(t *testing.T) {
var (
probeManager = probetest.FakeManager{}
Expand Down Expand Up @@ -681,7 +698,7 @@ func Test_managerImpl_processShutdownEvent(t *testing.T) {
l := klog.Level(1)
l.Set("1")
// hijack the klog output
tmpWriteBuffer := bytes.NewBuffer(nil)
tmpWriteBuffer := new(buffer)
klog.SetOutput(tmpWriteBuffer)
klog.LogToStderr(false)

Expand Down

0 comments on commit eaee96e

Please sign in to comment.