blob: 453584355469b9e56d7aaa863165e271b1ec162a [file] [log] [blame]
Matus Fabianed984382024-06-24 19:05:38 +02001package main
2
3import (
4 . "fd.io/hs-test/infra"
5 "fmt"
6 "github.com/edwarnicke/exechelper"
7 . "github.com/onsi/ginkgo/v2"
8 "os"
9 "strings"
10)
11
12func init() {
13 RegisterNginxTests(MirroringTest)
14 RegisterNoTopoTests(NginxHttp3Test, NginxAsServerTest, NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest,
15 NginxPerfCpsInterruptModeTest, NginxPerfRpsInterruptModeTest, NginxPerfWrkInterruptModeTest)
16}
17
18// broken when CPUS > 1
19func MirroringTest(s *NginxSuite) {
20 s.SkipIfMultiWorker()
21 proxyAddress := s.GetInterfaceByName(MirroringClientInterfaceName).Peer.Ip4AddressString()
22
23 path := "/64B.json"
24
25 testCommand := "wrk -c 20 -t 10 -d 10 http://" + proxyAddress + ":80" + path
26 s.Log(testCommand)
27 o, _ := exechelper.Output(testCommand)
28 s.Log(string(o))
29 s.AssertNotEmpty(o)
30
31 vppProxyContainer := s.GetContainerByName(VppProxyContainerName)
32 s.AssertEqual(0, vppProxyContainer.VppInstance.GetSessionStat("no lcl port"))
33}
34
35func NginxHttp3Test(s *NoTopoSuite) {
36 s.SkipUnlessExtendedTestsBuilt()
37
38 query := "index.html"
39 nginxCont := s.GetContainerByName("nginx-http3")
Adrian Villin25140012024-07-09 15:31:36 +020040 nginxCont.Run()
Matus Fabianed984382024-06-24 19:05:38 +020041
42 vpp := s.GetContainerByName("vpp").VppInstance
43 vpp.WaitForApp("nginx-", 5)
44 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
45
46 defer func() { os.Remove(query) }()
47 curlCont := s.GetContainerByName("curl")
48 args := fmt.Sprintf("curl --noproxy '*' --local-port 55444 --http3-only -k https://%s:8443/%s", serverAddress, query)
49 curlCont.ExtraRunningArgs = args
Adrian Villin25140012024-07-09 15:31:36 +020050 curlCont.Run()
51 o, err := curlCont.GetOutput()
Matus Fabianed984382024-06-24 19:05:38 +020052 s.Log(o)
Adrian Villin25140012024-07-09 15:31:36 +020053 s.AssertEmpty(err)
Matus Fabianed984382024-06-24 19:05:38 +020054 s.AssertContains(o, "<http>", "<http> not found in the result!")
55}
56func NginxAsServerTest(s *NoTopoSuite) {
57 query := "return_ok"
58 finished := make(chan error, 1)
59
60 nginxCont := s.GetContainerByName("nginx")
Adrian Villin25140012024-07-09 15:31:36 +020061 nginxCont.Run()
Matus Fabianed984382024-06-24 19:05:38 +020062
63 vpp := s.GetContainerByName("vpp").VppInstance
64 vpp.WaitForApp("nginx-", 5)
65
66 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
67
68 defer func() { os.Remove(query) }()
69 go func() {
70 defer GinkgoRecover()
71 s.StartWget(finished, serverAddress, "80", query, "")
72 }()
73 s.AssertNil(<-finished)
74}
75
76func parseString(s, pattern string) string {
77 temp := strings.Split(s, "\n")
78 for _, item := range temp {
79 if strings.Contains(item, pattern) {
80 return item
81 }
82 }
83 return ""
84}
85
86func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error {
87 nRequests := 1000000
88 nClients := 1000
89
90 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
91
92 vpp := s.GetContainerByName("vpp").VppInstance
93
94 nginxCont := s.GetContainerByName(SingleTopoContainerNginx)
Adrian Villin25140012024-07-09 15:31:36 +020095 nginxCont.Run()
Matus Fabianed984382024-06-24 19:05:38 +020096 vpp.WaitForApp("nginx-", 5)
97
98 if ab_or_wrk == "ab" {
99 abCont := s.GetContainerByName("ab")
100 args := fmt.Sprintf("-n %d -c %d", nRequests, nClients)
101 if mode == "rps" {
102 args += " -k"
103 } else if mode != "cps" {
104 return fmt.Errorf("invalid mode %s; expected cps/rps", mode)
105 }
106 // don't exit on socket receive errors
107 args += " -r"
108 args += " http://" + serverAddress + ":80/64B.json"
109 abCont.ExtraRunningArgs = args
Adrian Villin25140012024-07-09 15:31:36 +0200110 abCont.Run()
111 o, err := abCont.GetOutput()
Matus Fabianed984382024-06-24 19:05:38 +0200112 rps := parseString(o, "Requests per second:")
113 s.Log(rps)
Adrian Villin25140012024-07-09 15:31:36 +0200114 s.AssertContains(err, "Finished "+fmt.Sprint(nRequests))
Matus Fabianed984382024-06-24 19:05:38 +0200115 } else {
116 wrkCont := s.GetContainerByName("wrk")
117 args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients,
118 serverAddress)
119 wrkCont.ExtraRunningArgs = args
Adrian Villin25140012024-07-09 15:31:36 +0200120 wrkCont.Run()
121 s.Log("Please wait for 30s, test is running.")
122 o, err := wrkCont.GetOutput()
Matus Fabianed984382024-06-24 19:05:38 +0200123 rps := parseString(o, "requests")
124 s.Log(rps)
125 s.Log(err)
Adrian Villin25140012024-07-09 15:31:36 +0200126 s.AssertEmpty(err, "err: '%s', output: '%s'", err, o)
Matus Fabianed984382024-06-24 19:05:38 +0200127 }
128 return nil
129}
130
131func NginxPerfCpsInterruptModeTest(s *NoTopoSuite) {
132 NginxPerfCpsTest(s)
133}
134
135// unstable with multiple workers
136func NginxPerfCpsTest(s *NoTopoSuite) {
137 s.SkipIfMultiWorker()
138 s.AssertNil(runNginxPerf(s, "cps", "ab"))
139}
140
141func NginxPerfRpsInterruptModeTest(s *NoTopoSuite) {
142 NginxPerfRpsTest(s)
143}
144
145func NginxPerfRpsTest(s *NoTopoSuite) {
146 s.AssertNil(runNginxPerf(s, "rps", "ab"))
147}
148
149func NginxPerfWrkInterruptModeTest(s *NoTopoSuite) {
150 NginxPerfWrkTest(s)
151}
152
153func NginxPerfWrkTest(s *NoTopoSuite) {
154 s.AssertNil(runNginxPerf(s, "", "wrk"))
155}