Skip to content

Commit

Permalink
Extend testAttach delayOnceReader grace duration
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <[email protected]>
  • Loading branch information
apostasie committed Sep 25, 2024
1 parent 3e12ba0 commit 450817d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 1 addition & 17 deletions cmd/nerdctl/completion/completion_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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", ""),
Expand Down
27 changes: 22 additions & 5 deletions pkg/testutil/nerdtest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/testutil/testutil_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 450817d

Please sign in to comment.