Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | . "fd.io/hs-test/infra" |
| 5 | "fmt" |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 6 | . "github.com/onsi/ginkgo/v2" |
| 7 | "os" |
| 8 | "strings" |
| 9 | ) |
| 10 | |
| 11 | func init() { |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 12 | RegisterNoTopoTests(NginxHttp3Test, NginxAsServerTest, NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest, |
| 13 | NginxPerfCpsInterruptModeTest, NginxPerfRpsInterruptModeTest, NginxPerfWrkInterruptModeTest) |
| 14 | } |
| 15 | |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 16 | func NginxHttp3Test(s *NoTopoSuite) { |
| 17 | s.SkipUnlessExtendedTestsBuilt() |
| 18 | |
| 19 | query := "index.html" |
| 20 | nginxCont := s.GetContainerByName("nginx-http3") |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 21 | nginxCont.Run() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 22 | |
| 23 | vpp := s.GetContainerByName("vpp").VppInstance |
| 24 | vpp.WaitForApp("nginx-", 5) |
Matus Fabian | a647a83 | 2024-08-26 18:01:14 +0200 | [diff] [blame] | 25 | serverAddress := s.VppAddr() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 26 | |
| 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 Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 31 | curlCont.Run() |
| 32 | o, err := curlCont.GetOutput() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 33 | s.Log(o) |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 34 | s.AssertEmpty(err) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 35 | s.AssertContains(o, "<http>", "<http> not found in the result!") |
| 36 | } |
| 37 | func NginxAsServerTest(s *NoTopoSuite) { |
| 38 | query := "return_ok" |
| 39 | finished := make(chan error, 1) |
| 40 | |
| 41 | nginxCont := s.GetContainerByName("nginx") |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 42 | nginxCont.Run() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 43 | |
| 44 | vpp := s.GetContainerByName("vpp").VppInstance |
| 45 | vpp.WaitForApp("nginx-", 5) |
| 46 | |
Matus Fabian | a647a83 | 2024-08-26 18:01:14 +0200 | [diff] [blame] | 47 | serverAddress := s.VppAddr() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 48 | |
| 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 | |
| 57 | func 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 | |
| 67 | func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error { |
| 68 | nRequests := 1000000 |
| 69 | nClients := 1000 |
| 70 | |
Matus Fabian | a647a83 | 2024-08-26 18:01:14 +0200 | [diff] [blame] | 71 | serverAddress := s.VppAddr() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 72 | |
| 73 | vpp := s.GetContainerByName("vpp").VppInstance |
| 74 | |
| 75 | nginxCont := s.GetContainerByName(SingleTopoContainerNginx) |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 76 | nginxCont.Run() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 77 | 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 Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 91 | abCont.Run() |
| 92 | o, err := abCont.GetOutput() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 93 | rps := parseString(o, "Requests per second:") |
| 94 | s.Log(rps) |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 95 | s.AssertContains(err, "Finished "+fmt.Sprint(nRequests)) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 96 | } 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 Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 101 | wrkCont.Run() |
| 102 | s.Log("Please wait for 30s, test is running.") |
| 103 | o, err := wrkCont.GetOutput() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 104 | rps := parseString(o, "requests") |
| 105 | s.Log(rps) |
| 106 | s.Log(err) |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 107 | s.AssertEmpty(err, "err: '%s', output: '%s'", err, o) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 108 | } |
| 109 | return nil |
| 110 | } |
| 111 | |
| 112 | func NginxPerfCpsInterruptModeTest(s *NoTopoSuite) { |
| 113 | NginxPerfCpsTest(s) |
| 114 | } |
| 115 | |
| 116 | // unstable with multiple workers |
| 117 | func NginxPerfCpsTest(s *NoTopoSuite) { |
| 118 | s.SkipIfMultiWorker() |
| 119 | s.AssertNil(runNginxPerf(s, "cps", "ab")) |
| 120 | } |
| 121 | |
| 122 | func NginxPerfRpsInterruptModeTest(s *NoTopoSuite) { |
| 123 | NginxPerfRpsTest(s) |
| 124 | } |
| 125 | |
| 126 | func NginxPerfRpsTest(s *NoTopoSuite) { |
| 127 | s.AssertNil(runNginxPerf(s, "rps", "ab")) |
| 128 | } |
| 129 | |
| 130 | func NginxPerfWrkInterruptModeTest(s *NoTopoSuite) { |
| 131 | NginxPerfWrkTest(s) |
| 132 | } |
| 133 | |
| 134 | func NginxPerfWrkTest(s *NoTopoSuite) { |
| 135 | s.AssertNil(runNginxPerf(s, "", "wrk")) |
| 136 | } |