Skip to content

Commit

Permalink
Merge pull request #108193 from utkarsh348/myfeature
Browse files Browse the repository at this point in the history
Fixed race condition in test manager shutdown
  • Loading branch information
k8s-ci-robot committed Mar 27, 2022
2 parents 98eff19 + eaee96e commit d796dd7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pkg/kubelet/nodeshutdown/nodeshutdown_manager_linux_test.go
Expand Up @@ -617,6 +617,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 @@ -684,7 +701,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 d796dd7

Please sign in to comment.