mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
integration: add wait
Cherry-picked several WIP commits fromb0a592798f/ Originally-authored-by: Rodrigo Campos <rodrigoca@microsoft.com> Co-Authored-by: Kir Kolyshkin <kolyshkin@gmail.com> Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp> Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commitfb6e650ab9) Signed-off-by: Austin Vazquez <macedonv@amazon.com>
This commit is contained in:
committed by
Austin Vazquez
parent
357886087c
commit
4d9560d6df
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/docker/docker/testutil/fakecontext"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
"gotest.tools/v3/poll"
|
||||
"gotest.tools/v3/skip"
|
||||
)
|
||||
|
||||
@@ -85,6 +86,8 @@ func TestBuildSquashParent(t *testing.T) {
|
||||
container.WithImage(name),
|
||||
container.WithCmd("/bin/sh", "-c", "cat /hello"),
|
||||
)
|
||||
|
||||
poll.WaitOn(t, container.IsStopped(ctx, client, cid))
|
||||
reader, err := client.ContainerLogs(ctx, cid, containertypes.LogsOptions{
|
||||
ShowStdout: true,
|
||||
})
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/docker/docker/testutil/fakecontext"
|
||||
"github.com/docker/docker/testutil/fixtures/load"
|
||||
"gotest.tools/v3/assert"
|
||||
"gotest.tools/v3/poll"
|
||||
"gotest.tools/v3/skip"
|
||||
)
|
||||
|
||||
@@ -117,6 +118,8 @@ func TestBuildUserNamespaceValidateCapabilitiesAreV2(t *testing.T) {
|
||||
container.WithImage(imageTag),
|
||||
container.WithCmd("/sbin/getcap", "-n", "/bin/sleep"),
|
||||
)
|
||||
|
||||
poll.WaitOn(t, container.IsStopped(ctx, clientNoUserRemap, cid))
|
||||
logReader, err := clientNoUserRemap.ContainerLogs(ctx, cid, containertypes.LogsOptions{
|
||||
ShowStdout: true,
|
||||
})
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/docker/docker/testutil/daemon"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
"gotest.tools/v3/poll"
|
||||
"gotest.tools/v3/skip"
|
||||
)
|
||||
|
||||
@@ -54,6 +55,7 @@ func TestCreateWithCDIDevices(t *testing.T) {
|
||||
}
|
||||
assert.Check(t, is.DeepEqual(inspect.HostConfig.DeviceRequests, expectedRequests))
|
||||
|
||||
poll.WaitOn(t, container.IsStopped(ctx, apiClient, id))
|
||||
reader, err := apiClient.ContainerLogs(ctx, id, containertypes.LogsOptions{
|
||||
ShowStdout: true,
|
||||
})
|
||||
|
||||
@@ -23,6 +23,7 @@ func TestDiff(t *testing.T) {
|
||||
{Kind: containertypes.ChangeAdd, Path: "/foo/bar"},
|
||||
}
|
||||
|
||||
poll.WaitOn(t, container.IsStopped(ctx, apiClient, cID))
|
||||
items, err := apiClient.ContainerDiff(ctx, cID)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, expected, items)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -25,13 +26,25 @@ func TestNetworkNat(t *testing.T) {
|
||||
|
||||
ctx := setupTest(t)
|
||||
|
||||
msg := "it works"
|
||||
startServerContainer(ctx, t, msg, 8080)
|
||||
const msg = "it works"
|
||||
const port = 8080
|
||||
startServerContainer(ctx, t, msg, port)
|
||||
|
||||
endpoint := getExternalAddress(t)
|
||||
conn, err := net.Dial("tcp", net.JoinHostPort(endpoint.String(), "8080"))
|
||||
assert.NilError(t, err)
|
||||
defer conn.Close()
|
||||
|
||||
var conn net.Conn
|
||||
addr := net.JoinHostPort(endpoint.String(), strconv.Itoa(port))
|
||||
poll.WaitOn(t, func(t poll.LogT) poll.Result {
|
||||
var err error
|
||||
conn, err = net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
return poll.Continue("waiting for %s to be accessible: %v", addr, err)
|
||||
}
|
||||
return poll.Success()
|
||||
})
|
||||
defer func() {
|
||||
assert.Check(t, conn.Close())
|
||||
}()
|
||||
|
||||
data, err := io.ReadAll(conn)
|
||||
assert.NilError(t, err)
|
||||
@@ -43,12 +56,23 @@ func TestNetworkLocalhostTCPNat(t *testing.T) {
|
||||
|
||||
ctx := setupTest(t)
|
||||
|
||||
msg := "hi yall"
|
||||
startServerContainer(ctx, t, msg, 8081)
|
||||
const msg = "hi yall"
|
||||
const port = 8081
|
||||
startServerContainer(ctx, t, msg, port)
|
||||
|
||||
conn, err := net.Dial("tcp", "localhost:8081")
|
||||
assert.NilError(t, err)
|
||||
defer conn.Close()
|
||||
var conn net.Conn
|
||||
addr := net.JoinHostPort("localhost", strconv.Itoa(port))
|
||||
poll.WaitOn(t, func(t poll.LogT) poll.Result {
|
||||
var err error
|
||||
conn, err = net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
return poll.Continue("waiting for %s to be accessible: %v", addr, err)
|
||||
}
|
||||
return poll.Success()
|
||||
})
|
||||
defer func() {
|
||||
assert.Check(t, conn.Close())
|
||||
}()
|
||||
|
||||
data, err := io.ReadAll(conn)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/docker/docker/testutil/daemon"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
"gotest.tools/v3/poll"
|
||||
"gotest.tools/v3/skip"
|
||||
)
|
||||
|
||||
@@ -61,7 +62,8 @@ func TestUsernsCommit(t *testing.T) {
|
||||
clientUserRemap := dUserRemap.NewClientT(t)
|
||||
defer clientUserRemap.Close()
|
||||
|
||||
container.Run(ctx, t, clientUserRemap, container.WithName(t.Name()), container.WithImage("busybox"), container.WithCmd("sh", "-c", "echo hello world > /hello.txt && chown 1000:1000 /hello.txt"))
|
||||
cID := container.Run(ctx, t, clientUserRemap, container.WithName(t.Name()), container.WithImage("busybox"), container.WithCmd("sh", "-c", "echo hello world > /hello.txt && chown 1000:1000 /hello.txt"))
|
||||
poll.WaitOn(t, container.IsStopped(ctx, clientUserRemap, cID))
|
||||
img, err := clientUserRemap.ContainerCommit(ctx, t.Name(), containertypes.CommitOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
|
||||
@@ -9,10 +9,12 @@ import (
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
testContainer "github.com/docker/docker/integration/internal/container"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
"github.com/docker/docker/testutil"
|
||||
"github.com/docker/docker/testutil/daemon"
|
||||
"gotest.tools/v3/assert"
|
||||
"gotest.tools/v3/poll"
|
||||
)
|
||||
|
||||
// TestReadPluginNoRead tests that reads are supported even if the plugin isn't capable.
|
||||
@@ -65,6 +67,7 @@ func TestReadPluginNoRead(t *testing.T) {
|
||||
err = client.ContainerStart(ctx, c.ID, container.StartOptions{})
|
||||
assert.Assert(t, err)
|
||||
|
||||
poll.WaitOn(t, testContainer.IsStopped(ctx, client, c.ID))
|
||||
logs, err := client.ContainerLogs(ctx, c.ID, container.LogsOptions{ShowStdout: true})
|
||||
if !test.logsSupported {
|
||||
assert.Assert(t, err != nil)
|
||||
|
||||
Reference in New Issue
Block a user