github.com/rita33cool1/iot-system-gateway@v0.0.0-20200911033302-e65bde238cc5/docker-engine/integration/container/stop_test.go (about)

     1  package container // import "github.com/docker/docker/integration/container"
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"strings"
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/docker/docker/api/types"
    11  	"github.com/docker/docker/integration/internal/container"
    12  	"github.com/docker/docker/integration/internal/request"
    13  	"github.com/gotestyourself/gotestyourself/assert"
    14  	"github.com/gotestyourself/gotestyourself/icmd"
    15  	"github.com/gotestyourself/gotestyourself/poll"
    16  	"github.com/gotestyourself/gotestyourself/skip"
    17  )
    18  
    19  func TestStopContainerWithRestartPolicyAlways(t *testing.T) {
    20  	defer setupTest(t)()
    21  	client := request.NewAPIClient(t)
    22  	ctx := context.Background()
    23  
    24  	names := []string{"verifyRestart1-" + t.Name(), "verifyRestart2-" + t.Name()}
    25  	for _, name := range names {
    26  		container.Run(t, ctx, client, container.WithName(name), container.WithCmd("false"), func(c *container.TestContainerConfig) {
    27  			c.HostConfig.RestartPolicy.Name = "always"
    28  		})
    29  	}
    30  
    31  	for _, name := range names {
    32  		poll.WaitOn(t, container.IsInState(ctx, client, name, "running", "restarting"), poll.WithDelay(100*time.Millisecond))
    33  	}
    34  
    35  	for _, name := range names {
    36  		err := client.ContainerStop(ctx, name, nil)
    37  		assert.NilError(t, err)
    38  	}
    39  
    40  	for _, name := range names {
    41  		poll.WaitOn(t, container.IsStopped(ctx, client, name), poll.WithDelay(100*time.Millisecond))
    42  	}
    43  }
    44  
    45  func TestDeleteDevicemapper(t *testing.T) {
    46  	skip.IfCondition(t, testEnv.DaemonInfo.Driver != "devicemapper")
    47  
    48  	defer setupTest(t)()
    49  	client := request.NewAPIClient(t)
    50  	ctx := context.Background()
    51  
    52  	id := container.Run(t, ctx, client, container.WithName("foo-"+t.Name()), container.WithCmd("echo"))
    53  
    54  	poll.WaitOn(t, container.IsStopped(ctx, client, id), poll.WithDelay(100*time.Millisecond))
    55  
    56  	inspect, err := client.ContainerInspect(ctx, id)
    57  	assert.NilError(t, err)
    58  
    59  	deviceID := inspect.GraphDriver.Data["DeviceId"]
    60  
    61  	// Find pool name from device name
    62  	deviceName := inspect.GraphDriver.Data["DeviceName"]
    63  	devicePrefix := deviceName[:strings.LastIndex(deviceName, "-")]
    64  	devicePool := fmt.Sprintf("/dev/mapper/%s-pool", devicePrefix)
    65  
    66  	result := icmd.RunCommand("dmsetup", "message", devicePool, "0", fmt.Sprintf("delete %s", deviceID))
    67  	result.Assert(t, icmd.Success)
    68  
    69  	err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{})
    70  	assert.NilError(t, err)
    71  }