github.com/kaisenlinux/docker@v0.0.0-20230510090727-ea55db55fac7/engine/integration-cli/docker_cli_logs_bench_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"testing"
     7  	"time"
     8  )
     9  
    10  func (s *DockerSuite) BenchmarkLogsCLIRotateFollow(c *testing.B) {
    11  	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")
    12  	id := strings.TrimSpace(out)
    13  	ch := make(chan error, 1)
    14  	go func() {
    15  		ch <- nil
    16  		out, _, _ := dockerCmdWithError("logs", "-f", id)
    17  		// if this returns at all, it's an error
    18  		ch <- fmt.Errorf(out)
    19  	}()
    20  
    21  	<-ch
    22  	select {
    23  	case <-time.After(30 * time.Second):
    24  		// ran for 30 seconds with no problem
    25  		return
    26  	case err := <-ch:
    27  		if err != nil {
    28  			c.Fatal(err)
    29  		}
    30  	}
    31  }