Explorar o código

Update atomic run state with non-buffer channels

Matt Bolt %!s(int64=4) %!d(string=hai) anos
pai
achega
7368556c4f
Modificáronse 2 ficheiros con 10 adicións e 2 borrados
  1. 2 2
      pkg/util/atomic/atomicrunstate.go
  2. 8 0
      pkg/util/atomic/atomicrunstate_test.go

+ 2 - 2
pkg/util/atomic/atomicrunstate.go

@@ -23,7 +23,7 @@ func (ars *AtomicRunState) Start() bool {
 		return false
 	}
 
-	ars.stop = make(chan struct{}, 1)
+	ars.stop = make(chan struct{})
 	return true
 }
 
@@ -44,7 +44,7 @@ func (ars *AtomicRunState) Stop() bool {
 
 	if !ars.stopping && ars.stop != nil {
 		ars.stopping = true
-		ars.reset = make(chan struct{}, 1)
+		ars.reset = make(chan struct{})
 		close(ars.stop)
 		return true
 	}

+ 8 - 0
pkg/util/atomic/atomicrunstate_test.go

@@ -124,6 +124,14 @@ func TestContinuousConcurrentStartsAndStops(t *testing.T) {
 	// continuously try and start the ars on a tight loop
 	// throttled by OnStop and WaitForReset()
 	go func() {
+		defer func() {
+			if e := recover(); e != nil {
+				// sometimes the waitgroup will hit a negative value at the end of the test
+				// this is ok given the way the test behaves (chaos star/stop calls), so
+				// we can safely ignore.
+			}
+		}()
+
 		firstCycle := true
 		for {
 			ars.WaitForReset()