Browse Source

wait: make WaitTime robust against deadline collisions

Anthony Romano 9 years ago
parent
commit
c3f069c9fc
1 changed files with 10 additions and 2 deletions
  1. 10 2
      pkg/wait/wait_time.go

+ 10 - 2
pkg/wait/wait_time.go

@@ -43,8 +43,16 @@ func (tl *timeList) Wait(deadline time.Time) <-chan struct{} {
 	tl.l.Lock()
 	defer tl.l.Unlock()
 	ch := make(chan struct{}, 1)
-	// The given deadline SHOULD be unique.
-	tl.m[deadline.UnixNano()] = ch
+	// The given deadline SHOULD be unique but CI manages to get
+	// the same nano time in the unit tests.
+	nano := deadline.UnixNano()
+	for {
+		if tl.m[nano] == nil {
+			tl.m[nano] = ch
+			break
+		}
+		nano++
+	}
 	return ch
 }