blob: 7a6f5b3c182b5ebaa4f627261c85eed57a5701ee [file] [log] [blame]
Matus Fabianed984382024-06-24 19:05:38 +02001package main
2
3import (
Matus Fabianed984382024-06-24 19:05:38 +02004 "fmt"
Matus Fabianed984382024-06-24 19:05:38 +02005 "os"
6 "strings"
Adrian Villin5a4c7a92024-09-26 11:24:34 +02007
8 . "fd.io/hs-test/infra"
9 . "github.com/onsi/ginkgo/v2"
Matus Fabianed984382024-06-24 19:05:38 +020010)
11
12func init() {
Matus Fabianed984382024-06-24 19:05:38 +020013 RegisterNoTopoTests(NginxHttp3Test, NginxAsServerTest, NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest,
14 NginxPerfCpsInterruptModeTest, NginxPerfRpsInterruptModeTest, NginxPerfWrkInterruptModeTest)
Adrian Villin46ab0b22024-09-19 17:19:39 +020015 RegisterNoTopoSoloTests(NginxPerfRpsMultiThreadTest, NginxPerfCpsMultiThreadTest)
Matus Fabianed984382024-06-24 19:05:38 +020016}
17
Matus Fabianed984382024-06-24 19:05:38 +020018func NginxHttp3Test(s *NoTopoSuite) {
Matus Fabianed984382024-06-24 19:05:38 +020019 query := "index.html"
Adrian Villin7bae9b02024-10-02 15:07:40 +020020 nginxCont := s.GetContainerByName(NginxHttp3ContainerName)
Adrian Villin46ab0b22024-09-19 17:19:39 +020021
Adrian Villin7bae9b02024-10-02 15:07:40 +020022 nginxCont.Create()
Adrian Villin46ab0b22024-09-19 17:19:39 +020023 s.CreateNginxHttp3Config(nginxCont)
Adrian Villin7bae9b02024-10-02 15:07:40 +020024 nginxCont.Start()
Matus Fabianed984382024-06-24 19:05:38 +020025
26 vpp := s.GetContainerByName("vpp").VppInstance
27 vpp.WaitForApp("nginx-", 5)
Matus Fabiana647a832024-08-26 18:01:14 +020028 serverAddress := s.VppAddr()
Matus Fabianed984382024-06-24 19:05:38 +020029
30 defer func() { os.Remove(query) }()
31 curlCont := s.GetContainerByName("curl")
32 args := fmt.Sprintf("curl --noproxy '*' --local-port 55444 --http3-only -k https://%s:8443/%s", serverAddress, query)
33 curlCont.ExtraRunningArgs = args
Adrian Villin25140012024-07-09 15:31:36 +020034 curlCont.Run()
Adrian Villin7bae9b02024-10-02 15:07:40 +020035 body, stats := curlCont.GetOutput()
36 s.Log(body)
37 s.Log(stats)
38 s.AssertNotContains(stats, "refused")
39 s.AssertContains(stats, "100")
40 s.AssertContains(body, "<http>", "<http> not found in the result!")
Matus Fabianed984382024-06-24 19:05:38 +020041}
Adrian Villin7bae9b02024-10-02 15:07:40 +020042
Matus Fabianed984382024-06-24 19:05:38 +020043func NginxAsServerTest(s *NoTopoSuite) {
44 query := "return_ok"
45 finished := make(chan error, 1)
46
47 nginxCont := s.GetContainerByName("nginx")
Adrian Villin46ab0b22024-09-19 17:19:39 +020048 nginxCont.Create()
49 s.CreateNginxConfig(nginxCont, false)
50 s.AddNginxVclConfig(false)
51 nginxCont.Start()
Matus Fabianed984382024-06-24 19:05:38 +020052
53 vpp := s.GetContainerByName("vpp").VppInstance
54 vpp.WaitForApp("nginx-", 5)
55
Matus Fabiana647a832024-08-26 18:01:14 +020056 serverAddress := s.VppAddr()
Matus Fabianed984382024-06-24 19:05:38 +020057
58 defer func() { os.Remove(query) }()
59 go func() {
60 defer GinkgoRecover()
61 s.StartWget(finished, serverAddress, "80", query, "")
62 }()
63 s.AssertNil(<-finished)
64}
65
66func parseString(s, pattern string) string {
67 temp := strings.Split(s, "\n")
68 for _, item := range temp {
69 if strings.Contains(item, pattern) {
70 return item
71 }
72 }
73 return ""
74}
75
Adrian Villin46ab0b22024-09-19 17:19:39 +020076func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string, multiThreadWorkers bool) error {
Matus Fabianed984382024-06-24 19:05:38 +020077 nRequests := 1000000
78 nClients := 1000
79
Matus Fabiana647a832024-08-26 18:01:14 +020080 serverAddress := s.VppAddr()
Matus Fabianed984382024-06-24 19:05:38 +020081
82 vpp := s.GetContainerByName("vpp").VppInstance
83
84 nginxCont := s.GetContainerByName(SingleTopoContainerNginx)
Adrian Villin46ab0b22024-09-19 17:19:39 +020085 nginxCont.Create()
86 s.AddNginxVclConfig(multiThreadWorkers)
87 s.CreateNginxConfig(nginxCont, multiThreadWorkers)
88 nginxCont.Start()
Matus Fabianed984382024-06-24 19:05:38 +020089 vpp.WaitForApp("nginx-", 5)
90
91 if ab_or_wrk == "ab" {
92 abCont := s.GetContainerByName("ab")
93 args := fmt.Sprintf("-n %d -c %d", nRequests, nClients)
94 if mode == "rps" {
95 args += " -k"
96 } else if mode != "cps" {
97 return fmt.Errorf("invalid mode %s; expected cps/rps", mode)
98 }
99 // don't exit on socket receive errors
100 args += " -r"
101 args += " http://" + serverAddress + ":80/64B.json"
102 abCont.ExtraRunningArgs = args
Adrian Villin46ab0b22024-09-19 17:19:39 +0200103 s.Log("Test might take up to 2 minutes to finish. Please wait")
Adrian Villin25140012024-07-09 15:31:36 +0200104 abCont.Run()
105 o, err := abCont.GetOutput()
Matus Fabianed984382024-06-24 19:05:38 +0200106 rps := parseString(o, "Requests per second:")
107 s.Log(rps)
Adrian Villin25140012024-07-09 15:31:36 +0200108 s.AssertContains(err, "Finished "+fmt.Sprint(nRequests))
Matus Fabianed984382024-06-24 19:05:38 +0200109 } else {
110 wrkCont := s.GetContainerByName("wrk")
111 args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients,
112 serverAddress)
113 wrkCont.ExtraRunningArgs = args
Adrian Villin25140012024-07-09 15:31:36 +0200114 wrkCont.Run()
115 s.Log("Please wait for 30s, test is running.")
116 o, err := wrkCont.GetOutput()
Matus Fabianed984382024-06-24 19:05:38 +0200117 rps := parseString(o, "requests")
118 s.Log(rps)
119 s.Log(err)
Adrian Villin25140012024-07-09 15:31:36 +0200120 s.AssertEmpty(err, "err: '%s', output: '%s'", err, o)
Matus Fabianed984382024-06-24 19:05:38 +0200121 }
122 return nil
123}
124
125func NginxPerfCpsInterruptModeTest(s *NoTopoSuite) {
126 NginxPerfCpsTest(s)
127}
128
Adrian Villin46ab0b22024-09-19 17:19:39 +0200129func NginxPerfCpsMultiThreadTest(s *NoTopoSuite) {
130 s.AssertNil(runNginxPerf(s, "cps", "ab", true))
131}
132
Matus Fabianed984382024-06-24 19:05:38 +0200133func NginxPerfCpsTest(s *NoTopoSuite) {
Adrian Villin46ab0b22024-09-19 17:19:39 +0200134 s.AssertNil(runNginxPerf(s, "cps", "ab", false))
Matus Fabianed984382024-06-24 19:05:38 +0200135}
136
137func NginxPerfRpsInterruptModeTest(s *NoTopoSuite) {
138 NginxPerfRpsTest(s)
139}
140
Adrian Villin46ab0b22024-09-19 17:19:39 +0200141func NginxPerfRpsMultiThreadTest(s *NoTopoSuite) {
142 s.AssertNil(runNginxPerf(s, "rps", "ab", true))
143}
144
Matus Fabianed984382024-06-24 19:05:38 +0200145func NginxPerfRpsTest(s *NoTopoSuite) {
Adrian Villin46ab0b22024-09-19 17:19:39 +0200146 s.AssertNil(runNginxPerf(s, "rps", "ab", false))
Matus Fabianed984382024-06-24 19:05:38 +0200147}
148
149func NginxPerfWrkInterruptModeTest(s *NoTopoSuite) {
150 NginxPerfWrkTest(s)
151}
152
153func NginxPerfWrkTest(s *NoTopoSuite) {
Adrian Villin46ab0b22024-09-19 17:19:39 +0200154 s.AssertNil(runNginxPerf(s, "", "wrk", false))
Matus Fabianed984382024-06-24 19:05:38 +0200155}