@@ -33,7 +33,6 @@ import (
3333 "testing"
3434 "time"
3535
36- "github.com/cenkalti/backoff"
3736 "github.com/docker/docker/api/types/mount"
3837 yaml "gopkg.in/yaml.v3"
3938 "gvisor.dev/gvisor/pkg/test/dockerutil"
@@ -500,18 +499,6 @@ func testDockerMatrix(ctx context.Context, t *testing.T, d *dockerutil.Container
500499 }
501500 name := strings .Join (nameParts , "_" )
502501 t .Run (name , func (t * testing.T ) {
503- if err := backoff .Retry (func () error {
504- output , err := dockerInGvisorExecOutput (ctx , d , []string {"docker" , "info" })
505- if err != nil {
506- return fmt .Errorf ("docker exec failed: %v" , err )
507- }
508- if ! strings .Contains (output , "Cannot connect to the Docker daemon" ) {
509- return nil
510- }
511- return fmt .Errorf ("docker daemon not ready" )
512- }, backoff .WithMaxRetries (backoff .NewConstantBackOff (100 * time .Millisecond ), 10 )); err != nil {
513- t .Fatalf ("failed to run docker test %q: %v" , name , err )
514- }
515502 def .testFunc (ctx , t , d , opts )
516503 })
517504 }
@@ -612,18 +599,6 @@ func removeDockerImage(ctx context.Context, imageName string, d *dockerutil.Cont
612599 return nil
613600}
614601
615- func dockerInGvisorExecOutput (ctx context.Context , d * dockerutil.Container , cmd []string ) (string , error ) {
616- execProc , err := d .ExecProcess (ctx , dockerutil.ExecOpts {}, cmd ... )
617- if err != nil {
618- return "" , fmt .Errorf ("docker exec failed: %v" , err )
619- }
620- output , err := execProc .Logs ()
621- if err != nil {
622- return "" , fmt .Errorf ("docker logs failed: %v" , err )
623- }
624- return output , nil
625- }
626-
627602func testDockerRun (ctx context.Context , t * testing.T , d * dockerutil.Container , opts dockerCommandOptions ) {
628603 cmd := []string {"docker" , "run" , "--rm" }
629604 if opts .hostNetwork {
@@ -633,12 +608,15 @@ func testDockerRun(ctx context.Context, t *testing.T, d *dockerutil.Container, o
633608 cmd = append (cmd , "--privileged" )
634609 }
635610 cmd = append (cmd , testAlpineImage , "sh" , "-c" , "apk add curl && apk info -d curl" )
636-
637- expectedOutput := "URL retrival utility and library"
638- output , err := dockerInGvisorExecOutput (ctx , d , cmd )
611+ execProc , err := d .ExecProcess (ctx , dockerutil.ExecOpts {}, cmd ... )
639612 if err != nil {
640613 t .Fatalf ("docker exec failed: %v" , err )
641614 }
615+ output , err := execProc .Logs ()
616+ if err != nil {
617+ t .Fatalf ("docker logs failed: %v" , err )
618+ }
619+ expectedOutput := "URL retrival utility and library"
642620 if ! strings .Contains (output , expectedOutput ) {
643621 t .Fatalf ("docker didn't get output expected: %q, got: %q" , expectedOutput , output )
644622 }
@@ -652,10 +630,14 @@ func testDockerBuild(ctx context.Context, t *testing.T, d *dockerutil.Container,
652630 imageName := strings .ToLower (strings .ReplaceAll (testutil .RandomID ("test_docker_build" ), "/" , "-" ))
653631 parts = append (parts , "-t" , imageName , "-f" , "-" , "." )
654632 cmd := strings .Join (parts , " " )
655- _ , err := dockerInGvisorExecOutput (ctx , d , [] string { "/bin/sh" , "-c" , cmd } )
633+ dockerBuildProc , err := d . ExecProcess (ctx , dockerutil. ExecOpts {}, "/bin/sh" , "-c" , cmd )
656634 if err != nil {
657635 t .Fatalf ("docker exec failed: %v" , err )
658636 }
637+ _ , err = dockerBuildProc .Logs ()
638+ if err != nil {
639+ t .Fatalf ("docker logs failed: %v" , err )
640+ }
659641 defer removeDockerImage (ctx , imageName , d )
660642 if err := checkDockerImage (ctx , imageName , d ); err != nil {
661643 t .Fatalf ("failed to find docker image: %v" , err )
@@ -680,9 +662,13 @@ func testDockerExec(ctx context.Context, t *testing.T, d *dockerutil.Container,
680662 }()
681663
682664 for i := 0 ; i < 10 ; i ++ {
683- inspectOutput , err := dockerInGvisorExecOutput (ctx , d , []string {"docker" , "container" , "inspect" , containerName })
665+ inspectProc , err := d .ExecProcess (ctx , dockerutil.ExecOpts {}, []string {"docker" , "container" , "inspect" , containerName }... )
666+ if err != nil {
667+ t .Fatalf ("docker container inspect failed: %v" , err )
668+ }
669+ inspectOutput , err := inspectProc .Logs ()
684670 if err != nil {
685- t .Fatalf ("docker exec failed: %v" , err )
671+ t .Fatalf ("docker logs failed: %v" , err )
686672 }
687673 if strings .Contains (inspectOutput , "\" Status\" : \" running\" " ) {
688674 break
@@ -696,11 +682,15 @@ func testDockerExec(ctx context.Context, t *testing.T, d *dockerutil.Container,
696682 }
697683 // Execute echo command in the container.
698684 execCmd = append (execCmd , containerName , "echo" , "exec in " + containerName )
699-
700- output , err := dockerInGvisorExecOutput (ctx , d , execCmd )
685+ execProc , err := d .ExecProcess (ctx , dockerutil.ExecOpts {}, execCmd ... )
701686 if err != nil {
702687 t .Fatalf ("docker exec failed: %v" , err )
703688 }
689+
690+ output , err := execProc .Logs ()
691+ if err != nil {
692+ t .Fatalf ("docker logs failed: %v" , err )
693+ }
704694 expectedOutput := "exec in " + containerName
705695 if ! strings .Contains (output , expectedOutput ) {
706696 t .Fatalf ("docker didn't get output expected: %q, got: %q" , expectedOutput , output )
0 commit comments