Browse code

Fix a race in pkg/integration.TestChannelBufferTimeout

Update #22965

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>

Akihiro Suda authored on 2016/05/25 15:21:26
Showing 1 changed files
... ...
@@ -510,9 +510,11 @@ func TestChannelBufferTimeout(t *testing.T) {
510 510
 	buf := &ChannelBuffer{make(chan []byte, 1)}
511 511
 	defer buf.Close()
512 512
 
513
+	done := make(chan struct{}, 1)
513 514
 	go func() {
514 515
 		time.Sleep(100 * time.Millisecond)
515 516
 		io.Copy(buf, strings.NewReader(expected))
517
+		done <- struct{}{}
516 518
 	}()
517 519
 
518 520
 	// Wait long enough
... ...
@@ -521,9 +523,7 @@ func TestChannelBufferTimeout(t *testing.T) {
521 521
 	if err == nil && err.Error() != "timeout reading from channel" {
522 522
 		t.Fatalf("Expected an error, got %s", err)
523 523
 	}
524
-
525
-	// Wait for the end :)
526
-	time.Sleep(150 * time.Millisecond)
524
+	<-done
527 525
 }
528 526
 
529 527
 func TestChannelBuffer(t *testing.T) {