blob: 00869b0c9b43d0c64d2a3d6a904751de0a67d555 [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")
40 s.AssertNil(nginxCont.Run())
41
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
50 o, err := curlCont.CombinedOutput()
51 s.Log(o)
52 s.AssertNil(err, fmt.Sprint(err))
53 s.AssertContains(o, "<http>", "<http> not found in the result!")
54}
55func NginxAsServerTest(s *NoTopoSuite) {
56 query := "return_ok"
57 finished := make(chan error, 1)
58
59 nginxCont := s.GetContainerByName("nginx")
60 s.AssertNil(nginxCont.Run())
61
62 vpp := s.GetContainerByName("vpp").VppInstance
63 vpp.WaitForApp("nginx-", 5)
64
65 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
66
67 defer func() { os.Remove(query) }()
68 go func() {
69 defer GinkgoRecover()
70 s.StartWget(finished, serverAddress, "80", query, "")
71 }()
72 s.AssertNil(<-finished)
73}
74
75func parseString(s, pattern string) string {
76 temp := strings.Split(s, "\n")
77 for _, item := range temp {
78 if strings.Contains(item, pattern) {
79 return item
80 }
81 }
82 return ""
83}
84
85func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error {
86 nRequests := 1000000
87 nClients := 1000
88
89 serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
90
91 vpp := s.GetContainerByName("vpp").VppInstance
92
93 nginxCont := s.GetContainerByName(SingleTopoContainerNginx)
94 s.AssertNil(nginxCont.Run())
95 vpp.WaitForApp("nginx-", 5)
96
97 if ab_or_wrk == "ab" {
98 abCont := s.GetContainerByName("ab")
99 args := fmt.Sprintf("-n %d -c %d", nRequests, nClients)
100 if mode == "rps" {
101 args += " -k"
102 } else if mode != "cps" {
103 return fmt.Errorf("invalid mode %s; expected cps/rps", mode)
104 }
105 // don't exit on socket receive errors
106 args += " -r"
107 args += " http://" + serverAddress + ":80/64B.json"
108 abCont.ExtraRunningArgs = args
109 o, err := abCont.CombinedOutput()
110 rps := parseString(o, "Requests per second:")
111 s.Log(rps)
112 s.Log(err)
113 s.AssertNil(err, "err: '%s', output: '%s'", err, o)
114 } else {
115 wrkCont := s.GetContainerByName("wrk")
116 args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients,
117 serverAddress)
118 wrkCont.ExtraRunningArgs = args
119 o, err := wrkCont.CombinedOutput()
120 rps := parseString(o, "requests")
121 s.Log(rps)
122 s.Log(err)
123 s.AssertNil(err, "err: '%s', output: '%s'", err, o)
124 }
125 return nil
126}
127
128func NginxPerfCpsInterruptModeTest(s *NoTopoSuite) {
129 NginxPerfCpsTest(s)
130}
131
132// unstable with multiple workers
133func NginxPerfCpsTest(s *NoTopoSuite) {
134 s.SkipIfMultiWorker()
135 s.AssertNil(runNginxPerf(s, "cps", "ab"))
136}
137
138func NginxPerfRpsInterruptModeTest(s *NoTopoSuite) {
139 NginxPerfRpsTest(s)
140}
141
142func NginxPerfRpsTest(s *NoTopoSuite) {
143 s.AssertNil(runNginxPerf(s, "rps", "ab"))
144}
145
146func NginxPerfWrkInterruptModeTest(s *NoTopoSuite) {
147 NginxPerfWrkTest(s)
148}
149
150func NginxPerfWrkTest(s *NoTopoSuite) {
151 s.AssertNil(runNginxPerf(s, "", "wrk"))
152}