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 from
b0a592798f/
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>
This commit is contained in:
committed by
Sebastiaan van Stijn
parent
d58e56eadb
commit
fb6e650ab9
@@ -17,6 +17,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"
|
||||
)
|
||||
|
||||
@@ -86,6 +87,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,
|
||||
})
|
||||
|
||||
@@ -19,6 +19,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"
|
||||
)
|
||||
|
||||
@@ -118,6 +119,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,
|
||||
})
|
||||
|
||||
@@ -15,6 +15,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"
|
||||
)
|
||||
|
||||
@@ -53,6 +54,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)
|
||||
@@ -40,16 +53,26 @@ func TestNetworkNat(t *testing.T) {
|
||||
|
||||
func TestNetworkLocalhostTCPNat(t *testing.T) {
|
||||
skip.If(t, testEnv.IsRemoteDaemon)
|
||||
skip.If(t, testEnv.GitHubActions, "FIXME: https://github.com/moby/moby/issues/41561")
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
"gotest.tools/v3/icmd"
|
||||
"gotest.tools/v3/poll"
|
||||
"gotest.tools/v3/skip"
|
||||
)
|
||||
|
||||
@@ -254,8 +255,16 @@ func TestProxy4To6(t *testing.T) {
|
||||
inspect := container.Inspect(ctx, t, c, serverId)
|
||||
hostPort := inspect.NetworkSettings.Ports["80/tcp"][0].HostPort
|
||||
|
||||
resp, err := http.Get("http://[::1]:" + hostPort)
|
||||
assert.NilError(t, err)
|
||||
var resp *http.Response
|
||||
addr := "http://[::1]:" + hostPort
|
||||
poll.WaitOn(t, func(t poll.LogT) poll.Result {
|
||||
var err error
|
||||
resp, err = http.Get(addr) // #nosec G107 -- Ignore "Potential HTTP request made with variable url"
|
||||
if err != nil {
|
||||
return poll.Continue("waiting for %s to be accessible: %v", addr, err)
|
||||
}
|
||||
return poll.Success()
|
||||
})
|
||||
assert.Check(t, is.Equal(resp.StatusCode, 404))
|
||||
}
|
||||
|
||||
|
||||
@@ -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