github.com/duglin/docker@v1.13.1/integration-cli/docker_cli_logs_bench_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"time"
     7  
     8  	"github.com/go-check/check"
     9  )
    10  
    11  func (s *DockerSuite) BenchmarkLogsCLIRotateFollow(c *check.C) {
    12  	out, _ := dockerCmd(c, "run", "-d", "--log-opt", "max-size=1b", "--log-opt", "max-file=10", "busybox", "sh", "-c", "while true; do usleep 50000; echo hello; done")
    13  	id := strings.TrimSpace(out)
    14  	ch := make(chan error, 1)
    15  	go func() {
    16  		ch <- nil
    17  		out, _, _ := dockerCmdWithError("logs", "-f", id)
    18  		// if this returns at all, it's an error
    19  		ch <- fmt.Errorf(out)
    20  	}()
    21  
    22  	<-ch
    23  	select {
    24  	case <-time.After(30 * time.Second):
    25  		// ran for 30 seconds with no problem
    26  		return
    27  	case err := <-ch:
    28  		if err != nil {
    29  			c.Fatal(err)
    30  		}
    31  	}
    32  }