mirror of
https://github.com/containers/podman.git
synced 2025-09-17 06:47:10 +08:00

There is no reason to define the same code every time in each file, just use global nodes. This diff should speak for itself. CleanupSecrets()/Volume() no longer call Cleanup() directly, as the global AfterEach node will always call Cleanup() this is no longer necessary. If one AfterEach() node fails it will still run the others. Also always unset the CONTAINERS_CONF env vars. This prevents people from forgetting to unset it. And fix the special CONTAINERS_CONF logic in the system connection tests, we do not want to preserve CONTAINERS_CONF anyway so just remove this logic. Ginkgo orders the BeforeEach and AfterEach nodes. They will be executed from the outer-most defined to inner-most. This means our global BeforeEach is always first. Only then the inner one (in the Describe() function in each file). For AfterEach it is inverted, from the inner to the outer. Also see https://onsi.github.io/ginkgo/#organizing-specs-with-container-nodes Signed-off-by: Paul Holzinger <pholzing@redhat.com>
116 lines
3.0 KiB
Go
116 lines
3.0 KiB
Go
package integration
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
"net/http"
|
|
"net/url"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/containers/podman/v4/utils"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
. "github.com/onsi/gomega/gexec"
|
|
)
|
|
|
|
var _ = Describe("podman system service", func() {
|
|
|
|
// The timeout used to for the service to respond. As shown in #12167,
|
|
// this may take some time on machines under high load.
|
|
var timeout = 30
|
|
|
|
Describe("verify timeout", func() {
|
|
It("of 2 seconds", func() {
|
|
SkipIfRemote("service subcommand not supported remotely")
|
|
|
|
address := url.URL{
|
|
Scheme: "tcp",
|
|
Host: net.JoinHostPort("localhost", randomPort()),
|
|
}
|
|
session := podmanTest.Podman([]string{
|
|
"system", "service", "--time=2", address.String(),
|
|
})
|
|
defer session.Kill()
|
|
|
|
WaitForService(address)
|
|
Eventually(session, timeout).Should(Exit(0))
|
|
})
|
|
})
|
|
|
|
Describe("verify pprof endpoints", func() {
|
|
// Depends on pkg/api/server/server.go:255
|
|
const magicComment = "pprof service listening on"
|
|
|
|
It("are available", func() {
|
|
Skip("FIXME: Test is too flaky (#12624)")
|
|
SkipIfRemote("service subcommand not supported remotely")
|
|
|
|
address := url.URL{
|
|
Scheme: "tcp",
|
|
Host: net.JoinHostPort("localhost", randomPort()),
|
|
}
|
|
|
|
pprofPort := randomPort()
|
|
session := podmanTest.Podman([]string{
|
|
"system", "service", "--log-level=debug", "--time=0",
|
|
"--pprof-address=localhost:" + pprofPort, address.String(),
|
|
})
|
|
defer session.Kill()
|
|
|
|
WaitForService(address)
|
|
|
|
// Combined with test below we have positive/negative test for pprof
|
|
Expect(session.Err.Contents()).Should(ContainSubstring(magicComment))
|
|
|
|
heap := url.URL{
|
|
Scheme: "http",
|
|
Host: net.JoinHostPort("localhost", pprofPort),
|
|
Path: "/debug/pprof/heap",
|
|
RawQuery: "seconds=2",
|
|
}
|
|
resp, err := http.Get(heap.String())
|
|
Expect(err).ShouldNot(HaveOccurred())
|
|
defer resp.Body.Close()
|
|
Expect(resp).To(HaveHTTPStatus(http.StatusOK))
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
Expect(err).ShouldNot(HaveOccurred())
|
|
Expect(body).ShouldNot(BeEmpty())
|
|
|
|
session.Interrupt().Wait(time.Duration(timeout) * time.Second)
|
|
Eventually(session, timeout).Should(Exit(1))
|
|
})
|
|
|
|
It("are not available", func() {
|
|
Skip("FIXME: Test is too flaky (#12624)")
|
|
SkipIfRemote("service subcommand not supported remotely")
|
|
|
|
address := url.URL{
|
|
Scheme: "tcp",
|
|
Host: net.JoinHostPort("localhost", randomPort()),
|
|
}
|
|
|
|
session := podmanTest.Podman([]string{
|
|
"system", "service", "--log-level=debug", "--time=0", address.String(),
|
|
})
|
|
defer session.Kill()
|
|
|
|
WaitForService(address)
|
|
|
|
// Combined with test above we have positive/negative test for pprof
|
|
Expect(session.Err.Contents()).ShouldNot(ContainSubstring(magicComment))
|
|
|
|
session.Interrupt().Wait(time.Duration(timeout) * time.Second)
|
|
Eventually(session, timeout).Should(Exit(1))
|
|
})
|
|
})
|
|
})
|
|
|
|
// randomPort leans on the go net library to find an available port...
|
|
func randomPort() string {
|
|
port, err := utils.GetRandomPort()
|
|
Expect(err).ShouldNot(HaveOccurred())
|
|
return strconv.Itoa(port)
|
|
}
|