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" |
| 6 | "github.com/edwarnicke/exechelper" |
| 7 | . "github.com/onsi/ginkgo/v2" |
| 8 | "os" |
| 9 | "strings" |
| 10 | ) |
| 11 | |
| 12 | func init() { |
| 13 | RegisterNginxTests(MirroringTest) |
| 14 | RegisterNoTopoTests(NginxHttp3Test, NginxAsServerTest, NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest, |
| 15 | NginxPerfCpsInterruptModeTest, NginxPerfRpsInterruptModeTest, NginxPerfWrkInterruptModeTest) |
| 16 | } |
| 17 | |
| 18 | // broken when CPUS > 1 |
| 19 | func 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 | |
| 35 | func NginxHttp3Test(s *NoTopoSuite) { |
| 36 | s.SkipUnlessExtendedTestsBuilt() |
| 37 | |
| 38 | query := "index.html" |
| 39 | nginxCont := s.GetContainerByName("nginx-http3") |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 40 | nginxCont.Run() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 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 |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 50 | curlCont.Run() |
| 51 | o, err := curlCont.GetOutput() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 52 | s.Log(o) |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 53 | s.AssertEmpty(err) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 54 | s.AssertContains(o, "<http>", "<http> not found in the result!") |
| 55 | } |
| 56 | func NginxAsServerTest(s *NoTopoSuite) { |
| 57 | query := "return_ok" |
| 58 | finished := make(chan error, 1) |
| 59 | |
| 60 | nginxCont := s.GetContainerByName("nginx") |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 61 | nginxCont.Run() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 62 | |
| 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 | |
| 76 | func 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 | |
| 86 | func 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 Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 95 | nginxCont.Run() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 96 | 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 Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 110 | abCont.Run() |
| 111 | o, err := abCont.GetOutput() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 112 | rps := parseString(o, "Requests per second:") |
| 113 | s.Log(rps) |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 114 | s.AssertContains(err, "Finished "+fmt.Sprint(nRequests)) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 115 | } 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 Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 120 | wrkCont.Run() |
| 121 | s.Log("Please wait for 30s, test is running.") |
| 122 | o, err := wrkCont.GetOutput() |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 123 | rps := parseString(o, "requests") |
| 124 | s.Log(rps) |
| 125 | s.Log(err) |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 126 | s.AssertEmpty(err, "err: '%s', output: '%s'", err, o) |
Matus Fabian | ed98438 | 2024-06-24 19:05:38 +0200 | [diff] [blame] | 127 | } |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | func NginxPerfCpsInterruptModeTest(s *NoTopoSuite) { |
| 132 | NginxPerfCpsTest(s) |
| 133 | } |
| 134 | |
| 135 | // unstable with multiple workers |
| 136 | func NginxPerfCpsTest(s *NoTopoSuite) { |
| 137 | s.SkipIfMultiWorker() |
| 138 | s.AssertNil(runNginxPerf(s, "cps", "ab")) |
| 139 | } |
| 140 | |
| 141 | func NginxPerfRpsInterruptModeTest(s *NoTopoSuite) { |
| 142 | NginxPerfRpsTest(s) |
| 143 | } |
| 144 | |
| 145 | func NginxPerfRpsTest(s *NoTopoSuite) { |
| 146 | s.AssertNil(runNginxPerf(s, "rps", "ab")) |
| 147 | } |
| 148 | |
| 149 | func NginxPerfWrkInterruptModeTest(s *NoTopoSuite) { |
| 150 | NginxPerfWrkTest(s) |
| 151 | } |
| 152 | |
| 153 | func NginxPerfWrkTest(s *NoTopoSuite) { |
| 154 | s.AssertNil(runNginxPerf(s, "", "wrk")) |
| 155 | } |