summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-10-10 12:54:29 +0200
committerGitHub <noreply@github.com>2021-10-10 12:54:29 +0200
commit60c711f78956f4eda1f811757dc8b320e5e66d9f (patch)
tree851f1a5766e15066ba64b527bf26a85fb27f3554 /test
parentc47f714fe8193cd1ac90a9359da3ef177a6db7e1 (diff)
parent8d3aec9d08bddf486dcb30e7113777b9d0cc27bd (diff)
downloadpodman-60c711f78956f4eda1f811757dc8b320e5e66d9f.tar.gz
podman-60c711f78956f4eda1f811757dc8b320e5e66d9f.tar.bz2
podman-60c711f78956f4eda1f811757dc8b320e5e66d9f.zip
Merge pull request #11869 from jwhonce/wip/pprof
Enable /debug/pprof API service endpoints
Diffstat (limited to 'test')
-rw-r--r--test/e2e/system_service_test.go142
-rw-r--r--test/system/271-tcp-cors-server.bats2
2 files changed, 143 insertions, 1 deletions
diff --git a/test/e2e/system_service_test.go b/test/e2e/system_service_test.go
new file mode 100644
index 000000000..684ac56b4
--- /dev/null
+++ b/test/e2e/system_service_test.go
@@ -0,0 +1,142 @@
+package integration
+
+import (
+ "io/ioutil"
+ "net"
+ "net/http"
+ "net/url"
+ "strconv"
+ "time"
+
+ . "github.com/containers/podman/v3/test/utils"
+ "github.com/containers/podman/v3/utils"
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+ . "github.com/onsi/gomega/gexec"
+)
+
+var _ = Describe("podman system service", func() {
+ var podmanTest *PodmanTestIntegration
+
+ BeforeEach(func() {
+ tempdir, err := CreateTempDirInTempDir()
+ Expect(err).ShouldNot(HaveOccurred())
+
+ podmanTest = PodmanTestCreate(tempdir)
+ podmanTest.Setup()
+ })
+
+ AfterEach(func() {
+ podmanTest.Cleanup()
+ processTestResult(CurrentGinkgoTestDescription())
+ })
+
+ 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)
+
+ session.Wait(5 * time.Second)
+ Eventually(session, 5).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() {
+ 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=info", "--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 := ioutil.ReadAll(resp.Body)
+ Expect(err).ShouldNot(HaveOccurred())
+ Expect(body).ShouldNot(BeEmpty())
+
+ session.Interrupt().Wait(2 * time.Second)
+ Eventually(session, 2).Should(Exit(1))
+ })
+
+ It("are not available", func() {
+ SkipIfRemote("service subcommand not supported remotely")
+
+ address := url.URL{
+ Scheme: "tcp",
+ Host: net.JoinHostPort("localhost", randomPort()),
+ }
+
+ session := podmanTest.Podman([]string{
+ "system", "service", "--log-level=info", "--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(2 * time.Second)
+ Eventually(session, 2).Should(Exit(1))
+ })
+ })
+})
+
+// WaitForService blocks, waiting for some service listening on given host:port
+func WaitForService(address url.URL) {
+ // Wait for podman to be ready
+ var conn net.Conn
+ var err error
+ for i := 1; i <= 5; i++ {
+ conn, err = net.Dial("tcp", address.Host)
+ if err != nil {
+ // Podman not available yet...
+ time.Sleep(time.Duration(i) * time.Second)
+ }
+ }
+ Expect(err).ShouldNot(HaveOccurred())
+ conn.Close()
+}
+
+// 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)
+}
diff --git a/test/system/271-tcp-cors-server.bats b/test/system/271-tcp-cors-server.bats
index d8e4eb3df..be77afd40 100644
--- a/test/system/271-tcp-cors-server.bats
+++ b/test/system/271-tcp-cors-server.bats
@@ -38,7 +38,7 @@ SOCKET_FILE="$UNIT_DIR/$SERVICE_NAME.socket"
@test "podman system service - CORS enabled in logs" {
skip_if_remote "system service tests are meaningless over remote"
run_podman system service --log-level="debug" --cors="*" -t 1
- is "$output" ".*CORS Headers were set to \*.*" "debug log confirms CORS headers set"
+ is "$output" ".*CORS Headers were set to ..\*...*" "debug log confirms CORS headers set"
}
# vim: filetype=sh