github.com/containers/podman/v5@v5.1.0-rc1/test/e2e/system_service_test.go (about)

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