github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/system_service_test.go (about) 1 package integration 2 3 import ( 4 "io/ioutil" 5 "net" 6 "net/http" 7 "net/url" 8 "strconv" 9 "time" 10 11 . "github.com/hanks177/podman/v4/test/utils" 12 "github.com/hanks177/podman/v4/utils" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 . "github.com/onsi/gomega/gexec" 16 ) 17 18 var _ = Describe("podman system service", func() { 19 var podmanTest *PodmanTestIntegration 20 21 // The timeout used to for the service to respond. As shown in #12167, 22 // this may take some time on machines under high load. 23 var timeout = 30 24 25 BeforeEach(func() { 26 tempdir, err := CreateTempDirInTempDir() 27 Expect(err).ShouldNot(HaveOccurred()) 28 29 podmanTest = PodmanTestCreate(tempdir) 30 podmanTest.Setup() 31 }) 32 33 AfterEach(func() { 34 podmanTest.Cleanup() 35 processTestResult(CurrentGinkgoTestDescription()) 36 }) 37 38 Describe("verify timeout", func() { 39 It("of 2 seconds", func() { 40 SkipIfRemote("service subcommand not supported remotely") 41 42 address := url.URL{ 43 Scheme: "tcp", 44 Host: net.JoinHostPort("localhost", randomPort()), 45 } 46 session := podmanTest.Podman([]string{ 47 "system", "service", "--time=2", address.String(), 48 }) 49 defer session.Kill() 50 51 WaitForService(address) 52 Eventually(session, timeout).Should(Exit(0)) 53 }) 54 }) 55 56 Describe("verify pprof endpoints", func() { 57 // Depends on pkg/api/server/server.go:255 58 const magicComment = "pprof service listening on" 59 60 It("are available", func() { 61 Skip("FIXME: Test is too flaky (#12624)") 62 SkipIfRemote("service subcommand not supported remotely") 63 64 address := url.URL{ 65 Scheme: "tcp", 66 Host: net.JoinHostPort("localhost", randomPort()), 67 } 68 69 pprofPort := randomPort() 70 session := podmanTest.Podman([]string{ 71 "system", "service", "--log-level=debug", "--time=0", 72 "--pprof-address=localhost:" + pprofPort, address.String(), 73 }) 74 defer session.Kill() 75 76 WaitForService(address) 77 78 // Combined with test below we have positive/negative test for pprof 79 Expect(session.Err.Contents()).Should(ContainSubstring(magicComment)) 80 81 heap := url.URL{ 82 Scheme: "http", 83 Host: net.JoinHostPort("localhost", pprofPort), 84 Path: "/debug/pprof/heap", 85 RawQuery: "seconds=2", 86 } 87 resp, err := http.Get(heap.String()) 88 Expect(err).ShouldNot(HaveOccurred()) 89 defer resp.Body.Close() 90 Expect(resp).To(HaveHTTPStatus(http.StatusOK)) 91 92 body, err := ioutil.ReadAll(resp.Body) 93 Expect(err).ShouldNot(HaveOccurred()) 94 Expect(body).ShouldNot(BeEmpty()) 95 96 session.Interrupt().Wait(time.Duration(timeout) * time.Second) 97 Eventually(session, timeout).Should(Exit(1)) 98 }) 99 100 It("are not available", func() { 101 Skip("FIXME: Test is too flaky (#12624)") 102 SkipIfRemote("service subcommand not supported remotely") 103 104 address := url.URL{ 105 Scheme: "tcp", 106 Host: net.JoinHostPort("localhost", randomPort()), 107 } 108 109 session := podmanTest.Podman([]string{ 110 "system", "service", "--log-level=debug", "--time=0", address.String(), 111 }) 112 defer session.Kill() 113 114 WaitForService(address) 115 116 // Combined with test above we have positive/negative test for pprof 117 Expect(session.Err.Contents()).ShouldNot(ContainSubstring(magicComment)) 118 119 session.Interrupt().Wait(time.Duration(timeout) * time.Second) 120 Eventually(session, timeout).Should(Exit(1)) 121 }) 122 }) 123 }) 124 125 // randomPort leans on the go net library to find an available port... 126 func randomPort() string { 127 port, err := utils.GetRandomPort() 128 Expect(err).ShouldNot(HaveOccurred()) 129 return strconv.Itoa(port) 130 }