Merge pull request #218 from munnerz/test-race
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Enable go race detector and fix race in scheduler **What this PR does / why we need it**: Fixes a race condition in the scheduler package and enables the race detector in tests **Release note**: ```release-note Fix a race condition in the package responsible for scheduling renewals ```
This commit is contained in:
commit
28fc543db6
1
Makefile
1
Makefile
@ -76,6 +76,7 @@ $(CMDS):
|
||||
|
||||
go_test:
|
||||
go test -v \
|
||||
-race \
|
||||
$$(go list ./... | \
|
||||
grep -v '/vendor/' | \
|
||||
grep -v '/test/e2e' | \
|
||||
|
||||
@ -35,19 +35,18 @@ func NewScheduledWorkQueue(processFunc ProcessFunc) ScheduledWorkQueue {
|
||||
// Duration has come (since the time Add was called). If an existing Timer for
|
||||
// obj already exists, the previous timer will be cancelled.
|
||||
func (s *scheduledWorkQueue) Add(obj interface{}, duration time.Duration) {
|
||||
s.clearTimer(obj)
|
||||
// we call Forget before acquiring the workLock in order to avoid deadlock
|
||||
s.Forget(obj)
|
||||
s.workLock.Lock()
|
||||
defer s.workLock.Unlock()
|
||||
s.work[obj] = time.AfterFunc(duration, func() {
|
||||
defer s.clearTimer(obj)
|
||||
defer s.Forget(obj)
|
||||
s.processFunc(obj)
|
||||
})
|
||||
}
|
||||
|
||||
// Forget will cancel the timer for the given object, if the timer exists.
|
||||
func (s *scheduledWorkQueue) Forget(obj interface{}) {
|
||||
s.clearTimer(obj)
|
||||
}
|
||||
|
||||
func (s *scheduledWorkQueue) clearTimer(obj interface{}) {
|
||||
s.workLock.Lock()
|
||||
defer s.workLock.Unlock()
|
||||
if timer, ok := s.work[obj]; ok {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user