Skip to content

Commit d340ab0

Browse files
authored
Merge pull request containerd#3384 from apostasie/dev-testing-fix
Testing-rig fixes
2 parents 2968d45 + 76a828d commit d340ab0

File tree

8 files changed

+45
-18
lines changed

8 files changed

+45
-18
lines changed

.github/workflows/test-canary.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@ jobs:
112112
ctrdVersion: ${{ env.CONTAINERD_VERSION }}
113113
run: powershell hack/configure-windows-ci.ps1
114114
- name: "Run integration tests"
115-
run: go test -v ./cmd/...
115+
# See https://github.com/containerd/nerdctl/blob/main/docs/testing.md#about-parallelization
116+
run: go test -p 1 -v ./cmd/nerdctl/...

.github/workflows/test-kube.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
with:
2323
fetch-depth: 1
2424
- name: "Run Kubernetes integration tests"
25+
# See https://github.com/containerd/nerdctl/blob/main/docs/testing.md#about-parallelization
2526
run: |
2627
./hack/build-integration-kubernetes.sh
27-
sudo ./_output/nerdctl exec nerdctl-test-control-plane bash -c -- 'export TMPDIR="$HOME"/tmp; mkdir -p "$TMPDIR"; cd /nerdctl-source; /usr/local/go/bin/go test ./cmd/nerdctl/ -test.only-kubernetes'
28+
sudo ./_output/nerdctl exec nerdctl-test-control-plane bash -c -- 'export TMPDIR="$HOME"/tmp; mkdir -p "$TMPDIR"; cd /nerdctl-source; /usr/local/go/bin/go test -p 1 ./cmd/nerdctl/... -test.only-kubernetes'

.github/workflows/test.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,16 @@ jobs:
290290
timeout_minutes: 30
291291
max_attempts: 2
292292
retry_on: error
293-
command: go test -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.allow-kill-daemon
293+
# See https://github.com/containerd/nerdctl/blob/main/docs/testing.md#about-parallelization
294+
command: go test -p 1 -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.allow-kill-daemon
294295
- name: "Ensure that the IPv6 integration test suite is compatible with Docker"
295296
uses: nick-fields/retry@v3
296297
with:
297298
timeout_minutes: 30
298299
max_attempts: 2
299300
retry_on: error
300-
command: go test -timeout 20m -v -exec sudo ./cmd/nerdctl/... -args -test.target=docker -test.allow-kill-daemon -test.only-ipv6
301+
# See https://github.com/containerd/nerdctl/blob/main/docs/testing.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
301303

302304
test-integration-windows:
303305
runs-on: windows-2022
@@ -330,7 +332,8 @@ jobs:
330332
run: powershell hack/configure-windows-ci.ps1
331333
# TODO: Run unit tests
332334
- name: "Run integration tests"
333-
run: go test -v ./cmd/...
335+
# See https://github.com/containerd/nerdctl/blob/main/docs/testing.md#about-parallelization
336+
run: go test -p 1 -v ./cmd/nerdctl/...
334337

335338
test-integration-freebsd:
336339
name: FreeBSD

Dockerfile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ 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=github.com/containerd/nerdctl/v2/cmd/nerdctl/...", \
322-
"--", "-timeout=60m", "-args", "-test.allow-kill-daemon"]
321+
CMD ["gotestsum", "--format=testname", "--rerun-fails=2", "--packages=./cmd/nerdctl/...", \
322+
"--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon"]
323323

324324
FROM test-integration AS test-integration-rootless
325325
# Install SSH for creating systemd user session.
@@ -340,20 +340,19 @@ COPY ./Dockerfile.d/[email protected]_delegate.conf /etc/system
340340
# ipfs daemon for rootless containerd will be enabled in /test-integration-rootless.sh
341341
RUN systemctl disable test-integration-ipfs-offline
342342
VOLUME /home/rootless/.local/share
343-
RUN go test -o /usr/local/bin/nerdctl.test -c ./cmd/nerdctl
344343
COPY ./Dockerfile.d/test-integration-rootless.sh /
344+
RUN chmod a+rx /test-integration-rootless.sh
345345
CMD ["/test-integration-rootless.sh", \
346-
"gotestsum", "--format=testname", "--rerun-fails=2", "--raw-command", \
347-
"--", "/usr/local/go/bin/go", "tool", "test2json", "-t", "-p", "github.com/containerd/nerdctl/v2/cmd/nerdctl", \
348-
"/usr/local/bin/nerdctl.test", "-test.v", "-test.timeout=60m", "-test.allow-kill-daemon"]
346+
"gotestsum", "--format=testname", "--rerun-fails=2", "--packages=./cmd/nerdctl/...", \
347+
"--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon"]
349348

350349
# test for CONTAINERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=slirp4netns
351350
FROM test-integration-rootless AS test-integration-rootless-port-slirp4netns
352351
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
353352
RUN chown -R rootless:rootless /home/rootless/.config
354353

355354
FROM test-integration AS test-integration-ipv6
356-
CMD ["gotestsum", "--format=testname", "--rerun-fails=2", "--packages=github.com/containerd/nerdctl/v2/cmd/nerdctl/...", \
357-
"--", "-timeout=60m", "-args", "-test.allow-kill-daemon", "-test.only-ipv6"]
355+
CMD ["gotestsum", "--format=testname", "--rerun-fails=2", "--packages=./cmd/nerdctl/...", \
356+
"--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon", "-test.only-ipv6"]
358357

359358
FROM base AS demo

Dockerfile.d/test-integration-rootless.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,8 @@ EOF
5656
systemctl --user restart stargz-snapshotter.service
5757
export IPFS_PATH="/home/rootless/.local/share/ipfs"
5858
containerd-rootless-setuptool.sh install-bypass4netnsd
59-
exec "$@"
59+
# Once ssh-ed, we lost the Dockerfile working dir, so, get back in the nerdctl checkout
60+
cd /go/src/github.com/containerd/nerdctl
61+
# We also lose the PATH (and SendEnv=PATH would require sshd config changes)
62+
exec env PATH="/usr/local/go/bin:$PATH" "$@"
6063
fi

cmd/nerdctl/container_run_mount_linux_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func TestRunAnonymousVolume(t *testing.T) {
9898
func TestRunVolumeRelativePath(t *testing.T) {
9999
t.Parallel()
100100
base := testutil.NewBase(t)
101+
base.Dir = t.TempDir()
101102
base.Cmd("run", "--rm", "-v", "./foo:/mnt/foo", testutil.AlpineImage).AssertOK()
102103
base.Cmd("run", "--rm", "-v", "./foo", testutil.AlpineImage).AssertOK()
103104

docs/testing.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,34 @@ Be sure to first `make && sudo make install`
2121

2222
```bash
2323
# Test all with nerdctl (rootless mode, if running go as a non-root user)
24-
go test ./cmd/nerdctl/...
24+
go test -p 1 ./cmd/nerdctl/...
2525

2626
# Test all with nerdctl rootful
27-
go test -exec sudo ./cmd/nerdctl/...
27+
go test -p 1 -exec sudo ./cmd/nerdctl/...
2828

2929
# Test all with docker
30-
go test ./cmd/nerdctl/... -args -test.target=docker
30+
go test -p 1 ./cmd/nerdctl/... -args -test.target=docker
3131

3232
# Test just the tests(s) which names match TestVolume.*
33-
go test ./cmd/nerdctl/... -run "TestVolume.*"
33+
go test -p 1 ./cmd/nerdctl/... -run "TestVolume.*"
34+
# Or alternatively, just test the subpackage
35+
go test ./cmd/nerdctl/volume
3436
```
3537

38+
### About parallelization
39+
40+
By default, when `go test ./foo/...` finds subpackages, it does create _a separate test binary
41+
per sub-package_, and execute them _in parallel_.
42+
This effectively will make distinct tests in different subpackages to be executed in
43+
parallel, regardless of whether they called `t.Parallel` or not.
44+
45+
The `-p 1` flag does inhibit this behavior, and forces go to run each sub-package
46+
sequentially.
47+
48+
Note that this is different from the `--parallel` flag, which controls the amount of
49+
parallelization that a single go test binary will use when faced with tests that do
50+
explicitly allow it (with a call to `t.Parallel()`).
51+
3652
### Or test in a container
3753

3854
```bash

pkg/testutil/testutil.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type Base struct {
5858
Binary string
5959
Args []string
6060
Env []string
61+
Dir string
6162
}
6263

6364
// WithStdin sets the standard input of Cmd to the specified reader
@@ -70,6 +71,7 @@ func WithStdin(r io.Reader) func(*Cmd) {
7071
func (b *Base) Cmd(args ...string) *Cmd {
7172
icmdCmd := icmd.Command(b.Binary, append(b.Args, args...)...)
7273
icmdCmd.Env = b.Env
74+
icmdCmd.Dir = b.Dir
7375
cmd := &Cmd{
7476
Cmd: icmdCmd,
7577
Base: b,
@@ -83,6 +85,7 @@ func (b *Base) ComposeCmd(args ...string) *Cmd {
8385
binaryArgs := append(b.Args, append([]string{"compose"}, args...)...)
8486
icmdCmd := icmd.Command(binary, binaryArgs...)
8587
icmdCmd.Env = b.Env
88+
icmdCmd.Dir = b.Dir
8689
cmd := &Cmd{
8790
Cmd: icmdCmd,
8891
Base: b,

0 commit comments

Comments
 (0)