Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 4 | "fmt" |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 5 | "os" |
| 6 | "strings" |
Adrian Villin | 5a4c7a9 | 2024-09-26 11:24:34 +0200 | [diff] [blame] | 7 | |
| 8 | . "fd.io/hs-test/infra" |
| 9 | . "github.com/onsi/ginkgo/v2" |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | func init() { |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 13 | RegisterNoTopoTests(NginxHttp3Test, NginxAsServerTest, NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest, |
| 14 | NginxPerfCpsInterruptModeTest, NginxPerfRpsInterruptModeTest, NginxPerfWrkInterruptModeTest) |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 15 | RegisterNoTopoSoloTests(NginxPerfRpsMultiThreadTest, NginxPerfCpsMultiThreadTest) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 16 | } |
| 17 | |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 18 | func NginxHttp3Test(s *NoTopoSuite) { |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 19 | query := "index.html" |
Adrian Villin | 7bae9b0 | 2024-10-02 15:07:40 +0200 | [diff] [blame] | 20 | nginxCont := s.GetContainerByName(NginxHttp3ContainerName) |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 21 | |
Adrian Villin | 7bae9b0 | 2024-10-02 15:07:40 +0200 | [diff] [blame] | 22 | nginxCont.Create() |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 23 | s.CreateNginxHttp3Config(nginxCont) |
Adrian Villin | 7bae9b0 | 2024-10-02 15:07:40 +0200 | [diff] [blame] | 24 | nginxCont.Start() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 25 | |
| 26 | vpp := s.GetContainerByName("vpp").VppInstance |
| 27 | vpp.WaitForApp("nginx-", 5) |
Matus Fabian | a647a83 | 2024-08-26 18:01:14 +0200 | [diff] [blame] | 28 | serverAddress := s.VppAddr() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 29 | |
| 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 Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 34 | curlCont.Run() |
Adrian Villin | 7bae9b0 | 2024-10-02 15:07:40 +0200 | [diff] [blame] | 35 | 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 Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 41 | } |
Adrian Villin | 7bae9b0 | 2024-10-02 15:07:40 +0200 | [diff] [blame] | 42 | |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 43 | func NginxAsServerTest(s *NoTopoSuite) { |
| 44 | query := "return_ok" |
| 45 | finished := make(chan error, 1) |
| 46 | |
| 47 | nginxCont := s.GetContainerByName("nginx") |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 48 | nginxCont.Create() |
| 49 | s.CreateNginxConfig(nginxCont, false) |
| 50 | s.AddNginxVclConfig(false) |
| 51 | nginxCont.Start() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 52 | |
| 53 | vpp := s.GetContainerByName("vpp").VppInstance |
| 54 | vpp.WaitForApp("nginx-", 5) |
| 55 | |
Matus Fabian | a647a83 | 2024-08-26 18:01:14 +0200 | [diff] [blame] | 56 | serverAddress := s.VppAddr() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 57 | |
| 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 | |
| 66 | func 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 Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 76 | func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string, multiThreadWorkers bool) error { |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 77 | nRequests := 1000000 |
| 78 | nClients := 1000 |
| 79 | |
Matus Fabian | a647a83 | 2024-08-26 18:01:14 +0200 | [diff] [blame] | 80 | serverAddress := s.VppAddr() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 81 | |
| 82 | vpp := s.GetContainerByName("vpp").VppInstance |
| 83 | |
| 84 | nginxCont := s.GetContainerByName(SingleTopoContainerNginx) |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 85 | nginxCont.Create() |
| 86 | s.AddNginxVclConfig(multiThreadWorkers) |
| 87 | s.CreateNginxConfig(nginxCont, multiThreadWorkers) |
| 88 | nginxCont.Start() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 89 | 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 Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 103 | s.Log("Test might take up to 2 minutes to finish. Please wait") |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 104 | abCont.Run() |
| 105 | o, err := abCont.GetOutput() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 106 | rps := parseString(o, "Requests per second:") |
| 107 | s.Log(rps) |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 108 | s.AssertContains(err, "Finished "+fmt.Sprint(nRequests)) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 109 | } 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 Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 114 | wrkCont.Run() |
| 115 | s.Log("Please wait for 30s, test is running.") |
| 116 | o, err := wrkCont.GetOutput() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 117 | rps := parseString(o, "requests") |
| 118 | s.Log(rps) |
| 119 | s.Log(err) |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 120 | s.AssertEmpty(err, "err: '%s', output: '%s'", err, o) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 121 | } |
| 122 | return nil |
| 123 | } |
| 124 | |
| 125 | func NginxPerfCpsInterruptModeTest(s *NoTopoSuite) { |
| 126 | NginxPerfCpsTest(s) |
| 127 | } |
| 128 | |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 129 | func NginxPerfCpsMultiThreadTest(s *NoTopoSuite) { |
| 130 | s.AssertNil(runNginxPerf(s, "cps", "ab", true)) |
| 131 | } |
| 132 | |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 133 | func NginxPerfCpsTest(s *NoTopoSuite) { |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 134 | s.AssertNil(runNginxPerf(s, "cps", "ab", false)) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | func NginxPerfRpsInterruptModeTest(s *NoTopoSuite) { |
| 138 | NginxPerfRpsTest(s) |
| 139 | } |
| 140 | |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 141 | func NginxPerfRpsMultiThreadTest(s *NoTopoSuite) { |
| 142 | s.AssertNil(runNginxPerf(s, "rps", "ab", true)) |
| 143 | } |
| 144 | |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 145 | func NginxPerfRpsTest(s *NoTopoSuite) { |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 146 | s.AssertNil(runNginxPerf(s, "rps", "ab", false)) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | func NginxPerfWrkInterruptModeTest(s *NoTopoSuite) { |
| 150 | NginxPerfWrkTest(s) |
| 151 | } |
| 152 | |
| 153 | func NginxPerfWrkTest(s *NoTopoSuite) { |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 154 | s.AssertNil(runNginxPerf(s, "", "wrk", false)) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 155 | } |