github.com/lacework-dev/go-moby@v20.10.12+incompatible/integration/container/stop_test.go (about)

     1  package container // import "github.com/docker/docker/integration/container"
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/docker/docker/integration/internal/container"
     9  	"gotest.tools/v3/assert"
    10  	"gotest.tools/v3/poll"
    11  )
    12  
    13  func TestStopContainerWithRestartPolicyAlways(t *testing.T) {
    14  	defer setupTest(t)()
    15  	client := testEnv.APIClient()
    16  	ctx := context.Background()
    17  
    18  	names := []string{"verifyRestart1-" + t.Name(), "verifyRestart2-" + t.Name()}
    19  	for _, name := range names {
    20  		container.Run(ctx, t, client,
    21  			container.WithName(name),
    22  			container.WithCmd("false"),
    23  			container.WithRestartPolicy("always"),
    24  		)
    25  	}
    26  
    27  	for _, name := range names {
    28  		poll.WaitOn(t, container.IsInState(ctx, client, name, "running", "restarting"), poll.WithDelay(100*time.Millisecond))
    29  	}
    30  
    31  	for _, name := range names {
    32  		err := client.ContainerStop(ctx, name, nil)
    33  		assert.NilError(t, err)
    34  	}
    35  
    36  	for _, name := range names {
    37  		poll.WaitOn(t, container.IsStopped(ctx, client, name), poll.WithDelay(100*time.Millisecond))
    38  	}
    39  }