From 450817dbb30bd2dd45b3cb741439974db9a0ee02 Mon Sep 17 00:00:00 2001 From: apostasie Date: Wed, 25 Sep 2024 09:39:33 -0700 Subject: [PATCH] Extend testAttach delayOnceReader grace duration Signed-off-by: apostasie --- Dockerfile | 9 +++---- Makefile | 8 ++++++ .../completion/completion_linux_test.go | 18 +------------ pkg/testutil/nerdtest/test.go | 27 +++++++++++++++---- pkg/testutil/testutil_linux.go | 2 +- 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index d03b80b1483..e28f36ab602 100644 --- a/Dockerfile +++ b/Dockerfile @@ -280,6 +280,7 @@ FROM base AS test-integration ARG DEBIAN_FRONTEND=noninteractive # `expect` package contains `unbuffer(1)`, which is used for emulating TTY for testing RUN apt-get update -qq && apt-get install -qq --no-install-recommends \ + make \ expect \ git COPY --from=goversion /GOVERSION /GOVERSION @@ -290,6 +291,7 @@ ARG GOTESTSUM_VERSION RUN GOBIN=/usr/local/bin go install gotest.tools/gotestsum@${GOTESTSUM_VERSION} COPY . /go/src/github.com/containerd/nerdctl WORKDIR /go/src/github.com/containerd/nerdctl +RUN git config --global --add safe.directory /go/src/github.com/containerd/nerdctl VOLUME /tmp ENV CGO_ENABLED=0 # copy cosign binary for integration test @@ -318,8 +320,7 @@ RUN curl -o nydus-static.tgz -fsSL --proto '=https' --tlsv1.2 "https://github.co tar xzf nydus-static.tgz && \ mv nydus-static/nydus-image nydus-static/nydusd nydus-static/nydusify /usr/bin/ && \ rm nydus-static.tgz -CMD ["gotestsum", "--format=testname", "--packages=./cmd/nerdctl/...", \ - "--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon"] +CMD ["make", "test"] FROM test-integration AS test-integration-rootless # Install SSH for creating systemd user session. @@ -342,9 +343,7 @@ RUN systemctl disable test-integration-ipfs-offline VOLUME /home/rootless/.local/share COPY ./Dockerfile.d/test-integration-rootless.sh / RUN chmod a+rx /test-integration-rootless.sh -CMD ["/test-integration-rootless.sh", \ - "gotestsum", "--format=testname", "--packages=./cmd/nerdctl/...", \ - "--", "-timeout=60m", "-p", "1", "-args", "-test.allow-kill-daemon"] +CMD ["/test-integration-rootless.sh", "make", "test"] # test for CONTAINERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=slirp4netns FROM test-integration-rootless AS test-integration-rootless-port-slirp4netns diff --git a/Makefile b/Makefile index 0831c640047..0dfc2dfe805 100644 --- a/Makefile +++ b/Makefile @@ -86,6 +86,14 @@ lint-yaml: lint-shell: $(call recursive_wildcard,$(MAKEFILE_DIR)/,*.sh) shellcheck -a -x $^ +test: test-no-retry test-flaky + +test-flaky: + gotestsum --rerun-fails=2 --format=testname --packages=./cmd/nerdctl/builder,./cmd/nerdctl/compose,./cmd/nerdctl/container,./cmd/nerdctl/ipfs,./cmd/nerdctl/image -- -timeout=60m -p 1 -args -test.allow-kill-daemon + +test-no-retry: + go test $(shell go list ./cmd/nerdctl/... | grep -v nerdctl/builder | grep -v nerdctl/compose | grep -v nerdctl/container | grep -v nerdctl/ipfs | grep -v nerdctl/image) -timeout=60m -p 1 -args -test.allow-kill-daemon + binaries: nerdctl install: diff --git a/cmd/nerdctl/completion/completion_linux_test.go b/cmd/nerdctl/completion/completion_linux_test.go index 2ec8b062f7d..234c9a21ebc 100644 --- a/cmd/nerdctl/completion/completion_linux_test.go +++ b/cmd/nerdctl/completion/completion_linux_test.go @@ -31,6 +31,7 @@ func TestCompletion(t *testing.T) { Description: "Base completion", Require: test.Not(nerdtest.Docker), Setup: func(data test.Data, helpers test.Helpers) { + helpers.Ensure("pull", testutil.AlpineImage) helpers.Ensure("network", "create", data.Identifier()) helpers.Ensure("volume", "create", data.Identifier()) data.Set("identifier", data.Identifier()) @@ -176,23 +177,6 @@ func TestCompletion(t *testing.T) { }, Expected: test.Expects(0, nil, test.Contains("run\t")), }, - }, - } - - testCase.Run(t) -} - -// Test is privatized so that we can guarantee the image will not get rmi-ed -func TestCompletionPrivate(t *testing.T) { - nerdtest.Setup() - - testCase := &test.Case{ - Description: "With an image", - Require: test.Require(nerdtest.Private, test.Not(nerdtest.Docker)), - Setup: func(data test.Data, helpers test.Helpers) { - helpers.Ensure("pull", testutil.AlpineImage) - }, - SubTests: []*test.Case{ { Description: "run -i", Command: test.RunCommand("__complete", "run", "-i", ""), diff --git a/pkg/testutil/nerdtest/test.go b/pkg/testutil/nerdtest/test.go index a2f7a5bd3c2..b9fdcdef8a1 100644 --- a/pkg/testutil/nerdtest/test.go +++ b/pkg/testutil/nerdtest/test.go @@ -194,7 +194,8 @@ func nerdctlSetup(testCase *test.Case, t *testing.T) test.Command { testCase.Env["DOCKER_CONFIG"] = testCase.Data.TempDir() testCase.Env["NERDCTL_TOML"] = filepath.Join(testCase.Data.TempDir(), "nerdctl.toml") dt.WithConfig(HostsDir, test.ConfigValue(testCase.Data.TempDir())) - dt.WithConfig(DataRoot, test.ConfigValue(testCase.Data.TempDir())) + // Setting data root is more trouble than anything and does not significantly increase isolation + // dt.WithConfig(DataRoot, test.ConfigValue(testCase.Data.TempDir())) } testUtilBase = testutil.NewBaseWithNamespace(t, pvNamespace) if testUtilBase.Target == testutil.Docker { @@ -237,12 +238,28 @@ func nerdctlSetup(testCase *test.Case, t *testing.T) test.Command { } // If we were in a custom namespace, not inherited - make sure we clean up the namespace - // FIXME: this is broken, and custom namespaces are not cleaned properly if testUtilBase.Target == testutil.Nerdctl && pvNamespace != "" && !inherited { cleanup := func() { - cl := baseCommand.Clone() - cl.WithArgs("namespace", "remove", pvNamespace) - cl.Run(nil) + // Stop all containers, then prune everything + containerList := baseCommand.Clone() + containerList.WithArgs("ps", "-q") + containerList.Run(&test.Expected{ + Output: func(stdout string, info string, t *testing.T) { + if stdout != "" { + containerRm := baseCommand.Clone() + containerRm.WithArgs("rm", "-f", stdout) + containerRm.Run(&test.Expected{}) + } + }, + }) + + systemPrune := baseCommand.Clone() + systemPrune.WithArgs("system", "prune", "-f", "--all", "--volumes") + systemPrune.Run(&test.Expected{}) + + cleanNamespace := baseCommand.Clone() + cleanNamespace.WithArgs("namespace", "remove", pvNamespace) + cleanNamespace.Run(nil) } cleanup() t.Cleanup(cleanup) diff --git a/pkg/testutil/testutil_linux.go b/pkg/testutil/testutil_linux.go index 0629abbdac2..dce9431e021 100644 --- a/pkg/testutil/testutil_linux.go +++ b/pkg/testutil/testutil_linux.go @@ -126,7 +126,7 @@ func NewDelayOnceReader(wrapped io.Reader) io.Reader { func (r *delayOnceReader) Read(p []byte) (int, error) { // FIXME: this is obviously not exact science. At 1 second, it will fail regularly on the CI under load. - r.once.Do(func() { time.Sleep(2 * time.Second) }) + r.once.Do(func() { time.Sleep(5 * time.Second) }) n, err := r.wrapped.Read(p) if errors.Is(err, io.EOF) { time.Sleep(time.Second)