Skip to content

Commit 7829682

Browse files
committed
Revamp testing strategy
This: - slightly simplifies the Dockerfile - add a ./test-integration.sh script that will additionally provide information about slow tests - revamp lint testing on the CI (enable lint for non-linux) - removes nick retries entirely - separate flaky and non flaky runs in different steps Signed-off-by: apostasie <[email protected]>
1 parent 24d874c commit 7829682

File tree

7 files changed

+138
-76
lines changed

7 files changed

+138
-76
lines changed

.github/workflows/test-canary.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
- name: "Run unit tests"
6666
run: go test -v ./pkg/...
6767
- name: "Run integration tests"
68-
run: docker run -t --rm --privileged test-integration
68+
run: docker run -t --rm --privileged test-integration ./hack/test-integration.sh
6969

7070
windows:
7171
runs-on: windows-latest

.github/workflows/test.yml

Lines changed: 92 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,32 @@ on:
1111

1212
env:
1313
GO_VERSION: 1.23.x
14+
SHORT_TIMEOUT: 5
15+
LONG_TIMEOUT: 60
1416

1517
jobs:
16-
lint:
17-
runs-on: ubuntu-24.04
18-
timeout-minutes: 20
18+
lint-go:
19+
# Supposed to work: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#example-returning-a-json-data-type
20+
# Apparently does not
21+
# timeout-minutes: ${{ fromJSON(env.SHORT_TIMEOUT) }}
22+
timeout-minutes: 5
23+
name: lint-go ${{ matrix.goos }}
24+
runs-on: "${{ matrix.os }}"
25+
strategy:
26+
matrix:
27+
include:
28+
- os: ubuntu-24.04
29+
goos: linux
30+
- os: ubuntu-24.04
31+
goos: freebsd
32+
# FIXME: this is currently failing in a non-sensical way, so, running on linux instead...
33+
# - os: windows-2022
34+
- os: ubuntu-24.04
35+
goos: windows
36+
env:
37+
GOOS: "${{ matrix.goos }}"
1938
steps:
20-
- uses: actions/checkout@v4.2.1
39+
- uses: actions/checkout@v4
2140
with:
2241
fetch-depth: 1
2342
- uses: actions/setup-go@v5
@@ -26,24 +45,45 @@ jobs:
2645
check-latest: true
2746
cache: true
2847
- name: golangci-lint
29-
uses: golangci/golangci-lint-action@v6.1.1
48+
uses: golangci/golangci-lint-action@v6
3049
with:
31-
version: v1.60.1
3250
args: --verbose
33-
- name: yamllint-lint
51+
52+
lint-other:
53+
timeout-minutes: 5
54+
runs-on: ubuntu-24.04
55+
steps:
56+
- uses: actions/checkout@v4
57+
with:
58+
fetch-depth: 1
59+
- uses: actions/setup-go@v5
60+
with:
61+
go-version: ${{ env.GO_VERSION }}
62+
check-latest: true
63+
cache: true
64+
- name: yaml
3465
run: make lint-yaml
35-
- name: shellcheck
66+
- name: shell
3667
run: make lint-shell
3768
- name: go imports ordering
3869
run: |
3970
go install -v github.com/incu6us/goimports-reviser/v3@latest
4071
make lint-imports
4172
4273
test-unit:
43-
runs-on: ubuntu-24.04
44-
timeout-minutes: 20
74+
timeout-minutes: 5
75+
name: unit ${{ matrix.goos }}
76+
runs-on: "${{ matrix.os }}"
77+
strategy:
78+
matrix:
79+
include:
80+
# FIXME: currently disabled as a lot more work is required to make these tests pass on windows
81+
# - os: windows-2022
82+
# goos: windows
83+
- os: ubuntu-24.04
84+
goos: linux
4585
steps:
46-
- uses: actions/checkout@v4.2.1
86+
- uses: actions/checkout@v4
4787
with:
4888
fetch-depth: 1
4989
- uses: actions/setup-go@v5
@@ -52,11 +92,12 @@ jobs:
5292
check-latest: true
5393
cache: true
5494
- name: "Run unit tests"
55-
run: go test -v ./pkg/...
95+
run: make test-unit
5696

5797
test-integration:
98+
timeout-minutes: 60
99+
name: integration ${{ matrix.containerd }} ${{ matrix.runner }}
58100
runs-on: "${{ matrix.runner }}"
59-
timeout-minutes: 40
60101
strategy:
61102
fail-fast: false
62103
matrix:
@@ -78,7 +119,7 @@ jobs:
78119
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
79120
CONTAINERD_VERSION: "${{ matrix.containerd }}"
80121
steps:
81-
- uses: actions/checkout@v4.2.1
122+
- uses: actions/checkout@v4
82123
with:
83124
fetch-depth: 1
84125
- name: "Prepare integration test environment"
@@ -99,16 +140,16 @@ jobs:
99140
docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
100141
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
101142
- name: "Run integration tests"
102-
uses: nick-fields/retry@v3
103-
with:
104-
timeout_minutes: 30
105-
max_attempts: 2
106-
retry_on: error
107-
command: docker run -t --rm --privileged test-integration
143+
run: |
144+
docker run -t --rm --privileged test-integration ./hack/test-integration.sh
145+
- name: "Run integration tests (flaky)"
146+
run: |
147+
docker run -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky
108148
109149
test-integration-ipv6:
150+
timeout-minutes: 60
151+
name: ipv6 ${{ matrix.containerd }} ${{ matrix.ubuntu }}
110152
runs-on: "ubuntu-${{ matrix.ubuntu }}"
111-
timeout-minutes: 40
112153
strategy:
113154
fail-fast: false
114155
matrix:
@@ -120,7 +161,7 @@ jobs:
120161
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
121162
CONTAINERD_VERSION: "${{ matrix.containerd }}"
122163
steps:
123-
- uses: actions/checkout@v4.2.1
164+
- uses: actions/checkout@v4
124165
with:
125166
fetch-depth: 1
126167
- name: Enable ipv4 and ipv6 forwarding
@@ -133,7 +174,7 @@ jobs:
133174
echo '{"ipv6": true, "fixed-cidr-v6": "2001:db8:1::/64", "experimental": true, "ip6tables": true}' | sudo tee /etc/docker/daemon.json
134175
sudo systemctl restart docker
135176
- 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} .
177+
run: docker build -t test-integration --target test-integration --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
137178
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
138179
run: |
139180
sudo systemctl disable --now snapd.service snapd.socket
@@ -151,20 +192,16 @@ jobs:
151192
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
152193
- name: "Run integration tests"
153194
# The nested IPv6 network inside docker and qemu is complex and needs a bunch of sysctl config.
154-
# Therefore it's hard to debug why the IPv6 tests fail in such an isolation layer.
195+
# Therefore, it's hard to debug why the IPv6 tests fail in such an isolation layer.
155196
# On the other side, using the host network is easier at configuration.
156197
# Besides, each job is running on a different instance, which means using host network here
157198
# is safe and has no side effects on others.
158-
uses: nick-fields/retry@v3
159-
with:
160-
timeout_minutes: 30
161-
max_attempts: 2
162-
retry_on: error
163-
command: docker run --network host -t --rm --privileged test-integration-ipv6
199+
run: docker run --network host -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-ipv6
164200

165201
test-integration-rootless:
166-
runs-on: "ubuntu-${{ matrix.ubuntu }}"
167202
timeout-minutes: 60
203+
name: rootless ${{ matrix.containerd }} ${{ matrix.rootlesskit }} ${{ matrix.ubuntu }} ${{ matrix.target }}
204+
runs-on: "ubuntu-${{ matrix.ubuntu }}"
168205
strategy:
169206
fail-fast: false
170207
matrix:
@@ -207,7 +244,7 @@ jobs:
207244
}
208245
EOT
209246
sudo systemctl restart apparmor.service
210-
- uses: actions/checkout@v4.2.1
247+
- uses: actions/checkout@v4
211248
with:
212249
fetch-depth: 1
213250
- name: "Register QEMU (tonistiigi/binfmt)"
@@ -230,21 +267,18 @@ jobs:
230267
fi
231268
echo "WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622}" >> "$GITHUB_ENV"
232269
- name: "Test (network driver=slirp4netns, port driver=builtin)"
233-
uses: nick-fields/retry@v3
234-
with:
235-
timeout_minutes: 30
236-
max_attempts: 2
237-
retry_on: error
238-
command: docker run -t --rm --privileged -e WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622} ${TEST_TARGET}
270+
run: docker run -t --rm --privileged -e WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622} ${TEST_TARGET} /test-integration-rootless.sh ./hack/test-integration.sh
271+
- name: "Test (network driver=slirp4netns, port driver=builtin) (flaky)"
272+
run: docker run -t --rm --privileged -e WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622} ${TEST_TARGET} /test-integration-rootless.sh ./hack/test-integration.sh -test.only-flaky
239273

240274
cross:
275+
timeout-minutes: 5
241276
runs-on: ubuntu-24.04
242-
timeout-minutes: 40
243277
strategy:
244278
matrix:
245279
go-version: ["1.22.x", "1.23.x"]
246280
steps:
247-
- uses: actions/checkout@v4.2.1
281+
- uses: actions/checkout@v4
248282
with:
249283
fetch-depth: 1
250284
- uses: actions/setup-go@v5
@@ -256,10 +290,10 @@ jobs:
256290
run: GO_VERSION="$(echo ${{ matrix.go-version }} | sed -e s/.x//)" make binaries
257291

258292
test-integration-docker-compatibility:
293+
timeout-minutes: 60
259294
runs-on: ubuntu-24.04
260-
timeout-minutes: 45
261295
steps:
262-
- uses: actions/checkout@v4.2.1
296+
- uses: actions/checkout@v4
263297
with:
264298
fetch-depth: 1
265299
- uses: actions/setup-go@v5
@@ -284,31 +318,22 @@ jobs:
284318
- name: "Prepare integration test environment"
285319
run: |
286320
sudo apt-get install -y expect
321+
go install -v gotest.tools/gotestsum@v1
287322
- name: "Ensure that the integration test suite is compatible with Docker"
288-
uses: nick-fields/retry@v3
289-
with:
290-
timeout_minutes: 30
291-
max_attempts: 2
292-
retry_on: error
293-
# 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
323+
run: ./hack/test-integration.sh -test.target=docker
295324
- name: "Ensure that the IPv6 integration test suite is compatible with Docker"
296-
uses: nick-fields/retry@v3
297-
with:
298-
timeout_minutes: 30
299-
max_attempts: 2
300-
retry_on: error
301-
# 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
325+
run: ./hack/test-integration.sh -test.target=docker -test.only-ipv6
326+
- name: "Ensure that the integration test suite is compatible with Docker (flaky only)"
327+
run: ./hack/test-integration.sh -test.target=docker -test.only-flaky
303328

304329
test-integration-windows:
330+
timeout-minutes: 60
305331
runs-on: windows-2022
306-
timeout-minutes: 30
307332
defaults:
308333
run:
309334
shell: bash
310335
steps:
311-
- uses: actions/checkout@v4.2.1
336+
- uses: actions/checkout@v4
312337
with:
313338
fetch-depth: 1
314339
- uses: actions/setup-go@v5
@@ -317,7 +342,8 @@ jobs:
317342
cache: true
318343
check-latest: true
319344
- run: go install ./cmd/nerdctl
320-
- uses: actions/[email protected]
345+
- run: go install -v gotest.tools/gotestsum@v1
346+
- uses: actions/checkout@v4
321347
with:
322348
repository: containerd/containerd
323349
ref: v1.7.22
@@ -330,19 +356,21 @@ jobs:
330356
env:
331357
ctrdVersion: 1.7.22
332358
run: powershell hack/configure-windows-ci.ps1
333-
# TODO: Run unit tests
334359
- name: "Run integration tests"
335-
# See https://github.com/containerd/nerdctl/blob/main/docs/testing/README.md#about-parallelization
336-
run: go test -p 1 -v ./cmd/nerdctl/...
360+
run: |
361+
./hack/test-integration.sh
362+
- name: "Run integration tests (flaky)"
363+
run: |
364+
./hack/test-integration.sh -test.only-flaky
337365
338366
test-integration-freebsd:
367+
timeout-minutes: 60
339368
name: FreeBSD
340369
# ubuntu-24.04 lacks the vagrant package
341370
runs-on: ubuntu-22.04
342-
timeout-minutes: 20
343371

344372
steps:
345-
- uses: actions/checkout@v4.2.1
373+
- uses: actions/checkout@v4
346374
- uses: actions/cache@v4
347375
with:
348376
path: /root/.vagrant.d

Dockerfile

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ ARG DEBIAN_FRONTEND=noninteractive
281281
# `expect` package contains `unbuffer(1)`, which is used for emulating TTY for testing
282282
RUN apt-get update -qq && apt-get install -qq --no-install-recommends \
283283
expect \
284-
git
284+
git \
285+
make
285286
COPY --from=goversion /GOVERSION /GOVERSION
286287
ARG TARGETARCH
287288
RUN curl -fsSL --proto '=https' --tlsv1.2 https://golang.org/dl/$(cat /GOVERSION).linux-${TARGETARCH:-amd64}.tar.gz | tar xzvC /usr/local
@@ -318,8 +319,6 @@ RUN curl -o nydus-static.tgz -fsSL --proto '=https' --tlsv1.2 "https://github.co
318319
tar xzf nydus-static.tgz && \
319320
mv nydus-static/nydus-image nydus-static/nydusd nydus-static/nydusify /usr/bin/ && \
320321
rm nydus-static.tgz
321-
CMD ["gotestsum", "--format=testname", "--rerun-fails=2", "--packages=./cmd/nerdctl/...", \
322-
"--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon"]
323322

324323
FROM test-integration AS test-integration-rootless
325324
# Install SSH for creating systemd user session.
@@ -342,17 +341,10 @@ RUN systemctl disable test-integration-ipfs-offline
342341
VOLUME /home/rootless/.local/share
343342
COPY ./Dockerfile.d/test-integration-rootless.sh /
344343
RUN chmod a+rx /test-integration-rootless.sh
345-
CMD ["/test-integration-rootless.sh", \
346-
"gotestsum", "--format=testname", "--rerun-fails=2", "--packages=./cmd/nerdctl/...", \
347-
"--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon"]
348344

349345
# test for CONTAINERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=slirp4netns
350346
FROM test-integration-rootless AS test-integration-rootless-port-slirp4netns
351347
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
352348
RUN chown -R rootless:rootless /home/rootless/.config
353349

354-
FROM test-integration AS test-integration-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"]
357-
358350
FROM base AS demo

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ lint-yaml:
8686
lint-shell: $(call recursive_wildcard,$(MAKEFILE_DIR)/,*.sh)
8787
shellcheck -a -x $^
8888

89+
test-unit:
90+
go test -v $(MAKEFILE_DIR)/pkg/...
91+
8992
binaries: nerdctl
9093

9194
install:

docs/testing/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ explicitly allow it (with a call to `t.Parallel()`).
5858

5959
```bash
6060
docker build -t test-integration --target test-integration .
61-
docker run -t --rm --privileged test-integration
61+
docker run -t --rm --privileged test-integration ./hack/test-integration.sh
6262
```
6363

6464
### Principles

0 commit comments

Comments
 (0)