blob: fa6afda58fca1b53a31773bb5d9f5bf39492feb1 [file] [log] [blame]
Matus Fabianed984382024-06-24 19:05:38 +02001package main
2
3import (
4 . "fd.io/hs-test/infra"
5 "fmt"
Matus Fabianed984382024-06-24 19:05:38 +02006 . "github.com/onsi/ginkgo/v2"
7 "os"
8 "strings"
9)
10
11func init() {
Matus Fabianed984382024-06-24 19:05:38 +020012 RegisterNoTopoTests(NginxHttp3Test, NginxAsServerTest, NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest,
13 NginxPerfCpsInterruptModeTest, NginxPerfRpsInterruptModeTest, NginxPerfWrkInterruptModeTest)
14}
15
Matus Fabianed984382024-06-24 19:05:38 +020016func NginxHttp3Test(s *NoTopoSuite) {
17 s.SkipUnlessExtendedTestsBuilt()
18
19 query := "index.html"
20 nginxCont := s.GetContainerByName("nginx-http3")
Adrian Villin25140012024-07-09 15:31:36 +020021 nginxCont.Run()
Matus Fabianed984382024-06-24 19:05:38 +020022
23 vpp := s.GetContainerByName("vpp").VppInstance
24 vpp.WaitForApp("nginx-", 5)
Matus Fabiana647a832024-08-26 18:01:14 +020025 serverAddress := s.VppAddr()
Matus Fabianed984382024-06-24 19:05:38 +020026
27 defer func() { os.Remove(query) }()
28 curlCont := s.GetContainerByName("curl")
29 args := fmt.Sprintf("curl --noproxy '*' --local-port 55444 --http3-only -k https://%s:8443/%s", serverAddress, query)
30 curlCont.ExtraRunningArgs = args
Adrian Villin25140012024-07-09 15:31:36 +020031 curlCont.Run()
32 o, err := curlCont.GetOutput()
Matus Fabianed984382024-06-24 19:05:38 +020033 s.Log(o)
Adrian Villin25140012024-07-09 15:31:36 +020034 s.AssertEmpty(err)
Matus Fabianed984382024-06-24 19:05:38 +020035 s.AssertContains(o, "<http>", "<http> not found in the result!")
36}
37func NginxAsServerTest(s *NoTopoSuite) {
38 query := "return_ok"
39 finished := make(chan error, 1)
40
41 nginxCont := s.GetContainerByName("nginx")
Adrian Villin25140012024-07-09 15:31:36 +020042 nginxCont.Run()
Matus Fabianed984382024-06-24 19:05:38 +020043
44 vpp := s.GetContainerByName("vpp").VppInstance
45 vpp.WaitForApp("nginx-", 5)
46
Matus Fabiana647a832024-08-26 18:01:14 +020047 serverAddress := s.VppAddr()
Matus Fabianed984382024-06-24 19:05:38 +020048
49 defer func() { os.Remove(query) }()
50 go func() {
51 defer GinkgoRecover()
52 s.StartWget(finished, serverAddress, "80", query, "")
53 }()
54 s.AssertNil(<-finished)
55}
56
57func parseString(s, pattern string) string {
58 temp := strings.Split(s, "\n")
59 for _, item := range temp {
60 if strings.Contains(item, pattern) {
61 return item
62 }
63 }
64 return ""
65}
66
67func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error {
68 nRequests := 1000000
69 nClients := 1000
70
Matus Fabiana647a832024-08-26 18:01:14 +020071 serverAddress := s.VppAddr()
Matus Fabianed984382024-06-24 19:05:38 +020072
73 vpp := s.GetContainerByName("vpp").VppInstance
74
75 nginxCont := s.GetContainerByName(SingleTopoContainerNginx)
Adrian Villin25140012024-07-09 15:31:36 +020076 nginxCont.Run()
Matus Fabianed984382024-06-24 19:05:38 +020077 vpp.WaitForApp("nginx-", 5)
78
79 if ab_or_wrk == "ab" {
80 abCont := s.GetContainerByName("ab")
81 args := fmt.Sprintf("-n %d -c %d", nRequests, nClients)
82 if mode == "rps" {
83 args += " -k"
84 } else if mode != "cps" {
85 return fmt.Errorf("invalid mode %s; expected cps/rps", mode)
86 }
87 // don't exit on socket receive errors
88 args += " -r"
89 args += " http://" + serverAddress + ":80/64B.json"
90 abCont.ExtraRunningArgs = args
Adrian Villin25140012024-07-09 15:31:36 +020091 abCont.Run()
92 o, err := abCont.GetOutput()
Matus Fabianed984382024-06-24 19:05:38 +020093 rps := parseString(o, "Requests per second:")
94 s.Log(rps)
Adrian Villin25140012024-07-09 15:31:36 +020095 s.AssertContains(err, "Finished "+fmt.Sprint(nRequests))
Matus Fabianed984382024-06-24 19:05:38 +020096 } else {
97 wrkCont := s.GetContainerByName("wrk")
98 args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients,
99 serverAddress)
100 wrkCont.ExtraRunningArgs = args
Adrian Villin25140012024-07-09 15:31:36 +0200101 wrkCont.Run()
102 s.Log("Please wait for 30s, test is running.")
103 o, err := wrkCont.GetOutput()
Matus Fabianed984382024-06-24 19:05:38 +0200104 rps := parseString(o, "requests")
105 s.Log(rps)
106 s.Log(err)
Adrian Villin25140012024-07-09 15:31:36 +0200107 s.AssertEmpty(err, "err: '%s', output: '%s'", err, o)
Matus Fabianed984382024-06-24 19:05:38 +0200108 }
109 return nil
110}
111
112func NginxPerfCpsInterruptModeTest(s *NoTopoSuite) {
113 NginxPerfCpsTest(s)
114}
115
116// unstable with multiple workers
117func NginxPerfCpsTest(s *NoTopoSuite) {
118 s.SkipIfMultiWorker()
119 s.AssertNil(runNginxPerf(s, "cps", "ab"))
120}
121
122func NginxPerfRpsInterruptModeTest(s *NoTopoSuite) {
123 NginxPerfRpsTest(s)
124}
125
126func NginxPerfRpsTest(s *NoTopoSuite) {
127 s.AssertNil(runNginxPerf(s, "rps", "ab"))
128}
129
130func NginxPerfWrkInterruptModeTest(s *NoTopoSuite) {
131 NginxPerfWrkTest(s)
132}
133
134func NginxPerfWrkTest(s *NoTopoSuite) {
135 s.AssertNil(runNginxPerf(s, "", "wrk"))
136}