Skip to content

Commit d0ca83a

Browse files
committed
Test rework, part 4
Signed-off-by: apostasie <[email protected]>
1 parent e8ae137 commit d0ca83a

File tree

86 files changed

+6762
-3766
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+6762
-3766
lines changed

.github/workflows/test.yml

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ jobs:
8282
with:
8383
fetch-depth: 1
8484
- name: "Prepare integration test environment"
85-
run: docker build -t test-integration --target test-integration --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
85+
run: |
86+
docker build -t test-integration --target test-integration --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
87+
docker build -t test-integration-flaky --target test-integration-flaky --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
8688
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
8789
run: |
8890
sudo systemctl disable --now snapd.service snapd.socket
@@ -99,12 +101,15 @@ jobs:
99101
docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
100102
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
101103
- name: "Run integration tests"
104+
run: |
105+
docker run -t --rm --privileged test-integration
106+
- name: "Run integration tests: flaky"
102107
uses: nick-fields/retry@v3
103108
with:
104109
timeout_minutes: 30
105110
max_attempts: 2
106111
retry_on: error
107-
command: docker run -t --rm --privileged test-integration
112+
command: docker run -t --rm --privileged test-integration-flaky
108113

109114
test-integration-ipv6:
110115
runs-on: "ubuntu-${{ matrix.ubuntu }}"
@@ -133,7 +138,9 @@ jobs:
133138
echo '{"ipv6": true, "fixed-cidr-v6": "2001:db8:1::/64", "experimental": true, "ip6tables": true}' | sudo tee /etc/docker/daemon.json
134139
sudo systemctl restart docker
135140
- name: "Prepare integration test environment"
136-
run: docker build -t test-integration-ipv6 --target test-integration-ipv6 --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
141+
run: |
142+
docker build -t test-integration-ipv6 --target test-integration-ipv6 --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
143+
docker build -t test-integration-ipv6-flaky --target test-integration-ipv6-flaky --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
137144
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
138145
run: |
139146
sudo systemctl disable --now snapd.service snapd.socket
@@ -149,18 +156,20 @@ jobs:
149156
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64
150157
docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
151158
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
152-
- name: "Run integration tests"
153159
# The nested IPv6 network inside docker and qemu is complex and needs a bunch of sysctl config.
154160
# Therefore it's hard to debug why the IPv6 tests fail in such an isolation layer.
155161
# On the other side, using the host network is easier at configuration.
156162
# Besides, each job is running on a different instance, which means using host network here
157163
# is safe and has no side effects on others.
164+
- name: "Run integration tests"
165+
run: docker run --network host -t --rm --privileged test-integration-ipv6
166+
- name: "Run integration tests: flaky"
158167
uses: nick-fields/retry@v3
159168
with:
160169
timeout_minutes: 30
161170
max_attempts: 2
162171
retry_on: error
163-
command: docker run --network host -t --rm --privileged test-integration-ipv6
172+
command: docker run --network host -t --rm --privileged test-integration-ipv6-flaky
164173

165174
test-integration-rootless:
166175
runs-on: "ubuntu-${{ matrix.ubuntu }}"
@@ -220,7 +229,9 @@ jobs:
220229
docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
221230
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
222231
- name: "Prepare (network driver=slirp4netns, port driver=builtin)"
223-
run: docker build -t ${TEST_TARGET} --target ${TEST_TARGET} --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} --build-arg ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} .
232+
run: |
233+
docker build -t ${TEST_TARGET} --target ${TEST_TARGET} --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} --build-arg ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} .
234+
docker build -t ${TEST_TARGET}-flaky --target ${TEST_TARGET}-flaky --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} --build-arg ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} .
224235
- name: "Disable BuildKit for RootlessKit v1 (workaround for issue #622)"
225236
run: |
226237
# https://github.com/containerd/nerdctl/issues/622
@@ -230,12 +241,14 @@ jobs:
230241
fi
231242
echo "WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622}" >> "$GITHUB_ENV"
232243
- name: "Test (network driver=slirp4netns, port driver=builtin)"
244+
run: docker run -t --rm --privileged -e WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622} ${TEST_TARGET}
245+
- name: "Test (network driver=slirp4netns, port driver=builtin): flaky"
233246
uses: nick-fields/retry@v3
234247
with:
235248
timeout_minutes: 30
236249
max_attempts: 2
237250
retry_on: error
238-
command: docker run -t --rm --privileged -e WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622} ${TEST_TARGET}
251+
command: docker run -t --rm --privileged -e WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622} ${TEST_TARGET}-flaky
239252

240253
cross:
241254
runs-on: ubuntu-24.04
@@ -285,21 +298,25 @@ jobs:
285298
run: |
286299
sudo apt-get install -y expect
287300
- name: "Ensure that the integration test suite is compatible with Docker"
301+
run: go test -p 1 -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.allow-kill-daemon
302+
- name: "Ensure that the integration test suite is compatible with Docker: flaky"
288303
uses: nick-fields/retry@v3
289304
with:
290305
timeout_minutes: 30
291306
max_attempts: 2
292307
retry_on: error
293308
# See https://github.com/containerd/nerdctl/blob/main/docs/testing/README.md#about-parallelization
294-
command: go test -p 1 -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.allow-kill-daemon
309+
command: go test -p 1 -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.allow-kill-daemon -test.only-flaky
295310
- name: "Ensure that the IPv6 integration test suite is compatible with Docker"
311+
run: go test -p 1 -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.allow-kill-daemon -test.only-ipv6
312+
- name: "Ensure that the IPv6 integration test suite is compatible with Docker: flaky"
296313
uses: nick-fields/retry@v3
297314
with:
298315
timeout_minutes: 30
299316
max_attempts: 2
300317
retry_on: error
301318
# See https://github.com/containerd/nerdctl/blob/main/docs/testing/README.md#about-parallelization
302-
command: go test -p 1 -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.allow-kill-daemon -test.only-ipv6
319+
command: go test -p 1 -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.allow-kill-daemon -test.only-ipv6 -test.only-flaky
303320

304321
test-integration-windows:
305322
runs-on: windows-2022

Dockerfile

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,13 @@ RUN curl -o nydus-static.tgz -fsSL --proto '=https' --tlsv1.2 "https://github.co
318318
tar xzf nydus-static.tgz && \
319319
mv nydus-static/nydus-image nydus-static/nydusd nydus-static/nydusify /usr/bin/ && \
320320
rm nydus-static.tgz
321-
CMD ["gotestsum", "--format=testname", "--rerun-fails=2", "--packages=./cmd/nerdctl/...", \
321+
CMD ["gotestsum", "--format=testname", "--packages=./cmd/nerdctl/...", \
322322
"--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon"]
323323

324+
FROM test-integration AS test-integration-flaky
325+
CMD ["gotestsum", "--format=testname", "--rerun-fails=2", "--packages=./cmd/nerdctl/...", \
326+
"--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon", "-test.only-flaky"]
327+
324328
FROM test-integration AS test-integration-rootless
325329
# Install SSH for creating systemd user session.
326330
# (`sudo` does not work for this purpose,
@@ -343,16 +347,29 @@ VOLUME /home/rootless/.local/share
343347
COPY ./Dockerfile.d/test-integration-rootless.sh /
344348
RUN chmod a+rx /test-integration-rootless.sh
345349
CMD ["/test-integration-rootless.sh", \
346-
"gotestsum", "--format=testname", "--rerun-fails=2", "--packages=./cmd/nerdctl/...", \
350+
"gotestsum", "--format=testname", "--packages=./cmd/nerdctl/...", \
347351
"--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon"]
348352

353+
FROM test-integration-rootless AS test-integration-rootless-flaky
354+
CMD ["/test-integration-rootless.sh", \
355+
"gotestsum", "--format=testname", "--rerun-fails=2", "--packages=./cmd/nerdctl/...", \
356+
"--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon", "-test.only-flaky"]
357+
349358
# test for CONTAINERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=slirp4netns
350359
FROM test-integration-rootless AS test-integration-rootless-port-slirp4netns
351360
COPY ./Dockerfile.d/home_rootless_.config_systemd_user_containerd.service.d_port-slirp4netns.conf /home/rootless/.config/systemd/user/containerd.service.d/port-slirp4netns.conf
352361
RUN chown -R rootless:rootless /home/rootless/.config
353362

363+
FROM test-integration-rootless-flaky AS test-integration-rootless-port-slirp4netns-flaky
364+
COPY ./Dockerfile.d/home_rootless_.config_systemd_user_containerd.service.d_port-slirp4netns.conf /home/rootless/.config/systemd/user/containerd.service.d/port-slirp4netns.conf
365+
RUN chown -R rootless:rootless /home/rootless/.config
366+
354367
FROM test-integration AS test-integration-ipv6
355-
CMD ["gotestsum", "--format=testname", "--rerun-fails=2", "--packages=./cmd/nerdctl/...", \
368+
CMD ["gotestsum", "--format=testname", "--packages=./cmd/nerdctl/...", \
356369
"--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon", "-test.only-ipv6"]
357370

371+
FROM test-integration AS test-integration-ipv6-flaky
372+
CMD ["gotestsum", "--format=testname", "--rerun-fails=2", "--packages=./cmd/nerdctl/...", \
373+
"--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon", "-test.only-ipv6", "-test.only-flaky"]
374+
358375
FROM base AS demo

cmd/nerdctl/builder/builder_build_linux_test.go

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ package builder
1818

1919
import (
2020
"fmt"
21+
"strings"
2122
"testing"
2223

2324
"gotest.tools/v3/assert"
2425

25-
"github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
26+
testhelpers "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
2627
"github.com/containerd/nerdctl/v2/pkg/testutil"
28+
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
29+
"github.com/containerd/nerdctl/v2/pkg/testutil/test"
2730
)
2831

2932
func TestBuildContextWithOCILayout(t *testing.T) {
30-
testutil.RequiresBuild(t)
31-
testutil.RegisterBuildCacheCleanup(t)
33+
nerdtest.Setup()
3234

3335
var dockerBuilderArgs []string
3436
if testutil.IsDocker() {
@@ -38,48 +40,50 @@ func TestBuildContextWithOCILayout(t *testing.T) {
3840
dockerBuilderArgs = []string{"buildx", "--builder", builderName}
3941
}
4042

41-
base := testutil.NewBase(t)
42-
imageName := testutil.Identifier(t)
43-
ociLayout := "parent"
44-
parentImageName := fmt.Sprintf("%s-%s", imageName, ociLayout)
45-
46-
teardown := func() {
47-
base.Cmd("rmi", parentImageName, imageName).Run()
48-
}
49-
t.Cleanup(teardown)
50-
teardown()
51-
52-
dockerfile := fmt.Sprintf(`FROM %s
43+
testCase := &test.Case{
44+
Require: nerdtest.Build,
45+
Cleanup: func(data test.Data, helpers test.Helpers) {
46+
helpers.Anyhow("rmi", fmt.Sprintf("%s-parent", data.Identifier()))
47+
},
48+
Setup: func(data test.Data, helpers test.Helpers) {
49+
dockerfile := fmt.Sprintf(`FROM %s
5350
LABEL layer=oci-layout-parent
5451
CMD ["echo", "test-nerdctl-build-context-oci-layout-parent"]`, testutil.CommonImage)
55-
buildCtx := helpers.CreateBuildContext(t, dockerfile)
56-
57-
tarPath := fmt.Sprintf("%s/%s.tar", buildCtx, ociLayout)
58-
59-
// Create OCI archive from parent image.
60-
base.Cmd("build", buildCtx, "--tag", parentImageName).AssertOK()
61-
base.Cmd("image", "save", "--output", tarPath, parentImageName).AssertOK()
62-
63-
// Unpack OCI archive into OCI layout directory.
64-
ociLayoutDir := t.TempDir()
65-
err := helpers.ExtractTarFile(ociLayoutDir, tarPath)
66-
assert.NilError(t, err)
6752

68-
dockerfile = fmt.Sprintf(`FROM %s
69-
CMD ["echo", "test-nerdctl-build-context-oci-layout"]`, ociLayout)
70-
buildCtx = helpers.CreateBuildContext(t, dockerfile)
71-
72-
var buildArgs = []string{}
73-
if testutil.IsDocker() {
74-
buildArgs = dockerBuilderArgs
75-
}
76-
77-
buildArgs = append(buildArgs, "build", buildCtx, fmt.Sprintf("--build-context=%s=oci-layout://%s", ociLayout, ociLayoutDir), "--tag", imageName)
78-
if testutil.IsDocker() {
79-
// Need to load the container image from the builder to be able to run it.
80-
buildArgs = append(buildArgs, "--load")
53+
// FIXME: replace with a generic file creation helper - search for all occurrences of temp file creation
54+
buildCtx := testhelpers.CreateBuildContext(t, dockerfile)
55+
tarPath := fmt.Sprintf("%s/parent.tar", buildCtx)
56+
57+
helpers.Ensure("build", buildCtx, "--tag", fmt.Sprintf("%s-parent", data.Identifier()))
58+
helpers.Ensure("image", "save", "--output", tarPath, fmt.Sprintf("%s-parent", data.Identifier()))
59+
helpers.Custom("tar", "Cxf", data.TempDir(), tarPath).Run(&test.Expected{})
60+
},
61+
62+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
63+
dockerfile := `FROM parent
64+
CMD ["echo", "test-nerdctl-build-context-oci-layout"]`
65+
buildCtx := testhelpers.CreateBuildContext(t, dockerfile)
66+
var cmd test.TestableCommand
67+
if testutil.IsDocker() {
68+
cmd = helpers.Command(dockerBuilderArgs...)
69+
} else {
70+
cmd = helpers.Command()
71+
}
72+
cmd.WithArgs("build", buildCtx, fmt.Sprintf("--build-context=parent=oci-layout://%s", data.TempDir()), "--tag", data.Identifier())
73+
if testutil.IsDocker() {
74+
// Need to load the container image from the builder to be able to run it.
75+
cmd.WithArgs("--load")
76+
}
77+
return cmd
78+
},
79+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
80+
return &test.Expected{
81+
Output: func(stdout string, info string, t *testing.T) {
82+
assert.Assert(t, strings.Contains(helpers.Capture("run", "--rm", data.Identifier()), "test-nerdctl-build-context-oci-layout"), info)
83+
},
84+
}
85+
},
8186
}
8287

83-
base.Cmd(buildArgs...).AssertOK()
84-
base.Cmd("run", "--rm", imageName).AssertOutContains("test-nerdctl-build-context-oci-layout")
88+
testCase.Run(t)
8589
}

0 commit comments

Comments
 (0)