Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 1 | package main |
| 2 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 3 | import ( |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 4 | "fmt" |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 5 | "net/http" |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 6 | "os" |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 7 | "strings" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 8 | "time" |
| 9 | |
| 10 | . "github.com/onsi/ginkgo/v2" |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 11 | ) |
| 12 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 13 | func init() { |
| 14 | registerNsTests(HttpTpsTest) |
Matus Fabian | 3d00893 | 2024-05-13 10:29:11 +0200 | [diff] [blame] | 15 | registerVethTests(HttpCliTest, HttpCliConnectErrorTest) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 16 | registerNoTopoTests(NginxHttp3Test, NginxAsServerTest, |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 17 | NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest, HeaderServerTest, |
| 18 | HttpStaticMovedTest, HttpStaticNotFoundTest, HttpCliMethodNotAllowedTest, |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 19 | HttpCliBadRequestTest, HttpStaticPathTraversalTest) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 20 | registerNoTopoSoloTests(HttpStaticPromTest) |
| 21 | } |
| 22 | |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 23 | const wwwRootPath = "/tmp/www_root" |
| 24 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 25 | func HttpTpsTest(s *NsSuite) { |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 26 | iface := s.getInterfaceByName(clientInterface) |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 27 | client_ip := iface.ip4AddressString() |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 28 | port := "8080" |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 29 | finished := make(chan error, 1) |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 30 | clientNetns := s.getNetNamespaceByName("cln") |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 31 | |
| 32 | container := s.getContainerByName("vpp") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 33 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 34 | // configure vpp in the container |
| 35 | container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 36 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 37 | go func() { |
| 38 | defer GinkgoRecover() |
| 39 | s.startWget(finished, client_ip, port, "test_file_10M", clientNetns) |
| 40 | }() |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 41 | // wait for client |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 42 | err := <-finished |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 43 | s.assertNil(err, fmt.Sprint(err)) |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 44 | } |
| 45 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 46 | func HttpCliTest(s *VethsSuite) { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 47 | serverContainer := s.getContainerByName("server-vpp") |
| 48 | clientContainer := s.getContainerByName("client-vpp") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 49 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 50 | serverVeth := s.getInterfaceByName(serverInterfaceName) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 51 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 52 | serverContainer.vppInstance.vppctl("http cli server") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 53 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 54 | uri := "http://" + serverVeth.ip4AddressString() + "/80" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 55 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 56 | o := clientContainer.vppInstance.vppctl("http cli client" + |
Filip Tehlar | d894438 | 2023-11-27 13:28:36 +0100 | [diff] [blame] | 57 | " uri " + uri + " query /show/vlib/graph") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 58 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 59 | s.log(o) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 60 | s.assertContains(o, "<html>", "<html> not found in the result!") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 61 | } |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 62 | |
Matus Fabian | 3d00893 | 2024-05-13 10:29:11 +0200 | [diff] [blame] | 63 | func HttpCliConnectErrorTest(s *VethsSuite) { |
| 64 | clientContainer := s.getContainerByName("client-vpp") |
| 65 | |
| 66 | serverVeth := s.getInterfaceByName(serverInterfaceName) |
| 67 | |
| 68 | uri := "http://" + serverVeth.ip4AddressString() + "/80" |
| 69 | |
| 70 | o := clientContainer.vppInstance.vppctl("http cli client" + |
| 71 | " uri " + uri + " query /show/vlib/graph") |
| 72 | |
| 73 | s.log(o) |
| 74 | s.assertContains(o, "failed to connect") |
| 75 | } |
| 76 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 77 | func NginxHttp3Test(s *NoTopoSuite) { |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 78 | s.SkipUnlessExtendedTestsBuilt() |
| 79 | |
| 80 | query := "index.html" |
| 81 | nginxCont := s.getContainerByName("nginx-http3") |
| 82 | s.assertNil(nginxCont.run()) |
| 83 | |
| 84 | vpp := s.getContainerByName("vpp").vppInstance |
| 85 | vpp.waitForApp("nginx-", 5) |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 86 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 87 | |
| 88 | defer func() { os.Remove(query) }() |
| 89 | curlCont := s.getContainerByName("curl") |
Filip Tehlar | 87241fe | 2024-01-17 21:45:28 +0100 | [diff] [blame] | 90 | args := fmt.Sprintf("curl --noproxy '*' --local-port 55444 --http3-only -k https://%s:8443/%s", serverAddress, query) |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 91 | curlCont.extraRunningArgs = args |
| 92 | o, err := curlCont.combinedOutput() |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 93 | s.assertNil(err, fmt.Sprint(err)) |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 94 | s.assertContains(o, "<http>", "<http> not found in the result!") |
| 95 | } |
| 96 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 97 | func HttpStaticPromTest(s *NoTopoSuite) { |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 98 | finished := make(chan error, 1) |
| 99 | query := "stats.prom" |
| 100 | vpp := s.getContainerByName("vpp").vppInstance |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 101 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 102 | s.log(vpp.vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers")) |
| 103 | s.log(vpp.vppctl("prom enable")) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 104 | time.Sleep(time.Second * 5) |
| 105 | go func() { |
| 106 | defer GinkgoRecover() |
| 107 | s.startWget(finished, serverAddress, "80", query, "") |
| 108 | }() |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 109 | err := <-finished |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 110 | s.assertNil(err) |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 113 | func HttpStaticPathTraversalTest(s *NoTopoSuite) { |
| 114 | vpp := s.getContainerByName("vpp").vppInstance |
| 115 | vpp.container.exec("mkdir -p " + wwwRootPath) |
| 116 | vpp.container.exec("mkdir -p " + "/tmp/secret_folder") |
| 117 | vpp.container.createFile("/tmp/secret_folder/secret_file.txt", "secret") |
| 118 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
| 119 | s.log(vpp.vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug")) |
| 120 | |
| 121 | client := newHttpClient() |
| 122 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/../secret_folder/secret_file.txt", nil) |
| 123 | s.assertNil(err, fmt.Sprint(err)) |
| 124 | resp, err := client.Do(req) |
| 125 | s.assertNil(err, fmt.Sprint(err)) |
| 126 | defer resp.Body.Close() |
| 127 | s.assertEqual(404, resp.StatusCode) |
| 128 | } |
| 129 | |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 130 | func HttpStaticMovedTest(s *NoTopoSuite) { |
| 131 | vpp := s.getContainerByName("vpp").vppInstance |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 132 | vpp.container.exec("mkdir -p " + wwwRootPath + "/tmp.aaa") |
| 133 | vpp.container.createFile(wwwRootPath+"/tmp.aaa/index.html", "<http><body><p>Hello</p></body></http>") |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 134 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 135 | s.log(vpp.vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug")) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 136 | |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 137 | client := newHttpClient() |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 138 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/tmp.aaa", nil) |
| 139 | s.assertNil(err, fmt.Sprint(err)) |
| 140 | resp, err := client.Do(req) |
| 141 | s.assertNil(err, fmt.Sprint(err)) |
| 142 | defer resp.Body.Close() |
| 143 | s.assertEqual(301, resp.StatusCode) |
| 144 | s.assertNotEqual("", resp.Header.Get("Location")) |
| 145 | } |
| 146 | |
| 147 | func HttpStaticNotFoundTest(s *NoTopoSuite) { |
| 148 | vpp := s.getContainerByName("vpp").vppInstance |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 149 | vpp.container.exec("mkdir -p " + wwwRootPath) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 150 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 151 | s.log(vpp.vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug")) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 152 | |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 153 | client := newHttpClient() |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 154 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/notfound.html", nil) |
| 155 | s.assertNil(err, fmt.Sprint(err)) |
Matus Fabian | 595d8cb | 2024-05-17 11:28:43 +0200 | [diff] [blame] | 156 | resp, err := client.Do(req) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 157 | s.assertNil(err, fmt.Sprint(err)) |
| 158 | defer resp.Body.Close() |
| 159 | s.assertEqual(404, resp.StatusCode) |
| 160 | } |
| 161 | |
| 162 | func HttpCliMethodNotAllowedTest(s *NoTopoSuite) { |
Matus Fabian | 616201a | 2024-05-02 11:17:15 +0200 | [diff] [blame] | 163 | vpp := s.getContainerByName("vpp").vppInstance |
| 164 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
| 165 | vpp.vppctl("http cli server") |
| 166 | |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 167 | client := newHttpClient() |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 168 | req, err := http.NewRequest("POST", "http://"+serverAddress+":80/test", nil) |
Matus Fabian | 616201a | 2024-05-02 11:17:15 +0200 | [diff] [blame] | 169 | s.assertNil(err, fmt.Sprint(err)) |
Matus Fabian | 595d8cb | 2024-05-17 11:28:43 +0200 | [diff] [blame] | 170 | resp, err := client.Do(req) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 171 | s.assertNil(err, fmt.Sprint(err)) |
| 172 | defer resp.Body.Close() |
| 173 | s.assertEqual(405, resp.StatusCode) |
| 174 | // TODO: need to be fixed in http code |
| 175 | //s.assertNotEqual("", resp.Header.Get("Allow")) |
| 176 | } |
| 177 | |
| 178 | func HttpCliBadRequestTest(s *NoTopoSuite) { |
| 179 | vpp := s.getContainerByName("vpp").vppInstance |
| 180 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
| 181 | vpp.vppctl("http cli server") |
| 182 | |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 183 | client := newHttpClient() |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 184 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80", nil) |
| 185 | s.assertNil(err, fmt.Sprint(err)) |
Matus Fabian | 595d8cb | 2024-05-17 11:28:43 +0200 | [diff] [blame] | 186 | resp, err := client.Do(req) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 187 | s.assertNil(err, fmt.Sprint(err)) |
| 188 | defer resp.Body.Close() |
| 189 | s.assertEqual(400, resp.StatusCode) |
| 190 | } |
| 191 | |
| 192 | func HeaderServerTest(s *NoTopoSuite) { |
| 193 | vpp := s.getContainerByName("vpp").vppInstance |
| 194 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
| 195 | vpp.vppctl("http cli server") |
| 196 | |
Matus Fabian | 5409d33 | 2024-05-28 13:39:13 +0200 | [diff] [blame] | 197 | client := newHttpClient() |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 198 | req, err := http.NewRequest("GET", "http://"+serverAddress+":80/show/version", nil) |
| 199 | s.assertNil(err, fmt.Sprint(err)) |
Matus Fabian | 595d8cb | 2024-05-17 11:28:43 +0200 | [diff] [blame] | 200 | resp, err := client.Do(req) |
Matus Fabian | b7a9ed7 | 2024-05-10 16:20:40 +0200 | [diff] [blame] | 201 | s.assertNil(err, fmt.Sprint(err)) |
| 202 | defer resp.Body.Close() |
| 203 | s.assertEqual("http_cli_server", resp.Header.Get("Server")) |
Matus Fabian | 616201a | 2024-05-02 11:17:15 +0200 | [diff] [blame] | 204 | } |
| 205 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 206 | func NginxAsServerTest(s *NoTopoSuite) { |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 207 | query := "return_ok" |
| 208 | finished := make(chan error, 1) |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 209 | |
| 210 | nginxCont := s.getContainerByName("nginx") |
| 211 | s.assertNil(nginxCont.run()) |
| 212 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 213 | vpp := s.getContainerByName("vpp").vppInstance |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 214 | vpp.waitForApp("nginx-", 5) |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 215 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 216 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 217 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 218 | defer func() { os.Remove(query) }() |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 219 | go func() { |
| 220 | defer GinkgoRecover() |
| 221 | s.startWget(finished, serverAddress, "80", query, "") |
| 222 | }() |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 223 | s.assertNil(<-finished) |
| 224 | } |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 225 | |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 226 | func parseString(s, pattern string) string { |
| 227 | temp := strings.Split(s, "\n") |
| 228 | for _, item := range temp { |
| 229 | if strings.Contains(item, pattern) { |
| 230 | return item |
| 231 | } |
| 232 | } |
| 233 | return "" |
| 234 | } |
| 235 | |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 236 | func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error { |
| 237 | nRequests := 1000000 |
Filip Tehlar | dda1f68 | 2023-04-24 17:52:50 +0200 | [diff] [blame] | 238 | nClients := 1000 |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 239 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 240 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 241 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 242 | vpp := s.getContainerByName("vpp").vppInstance |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 243 | |
adrianvillin | fbf5f2b | 2024-02-13 03:26:25 -0500 | [diff] [blame] | 244 | nginxCont := s.getContainerByName(singleTopoContainerNginx) |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 245 | s.assertNil(nginxCont.run()) |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 246 | vpp.waitForApp("nginx-", 5) |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 247 | |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 248 | if ab_or_wrk == "ab" { |
| 249 | abCont := s.getContainerByName("ab") |
Adrian Villin | 7ad37b5 | 2024-06-05 05:53:50 -0400 | [diff] [blame^] | 250 | abCont.runDetached = true |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 251 | args := fmt.Sprintf("-n %d -c %d", nRequests, nClients) |
| 252 | if mode == "rps" { |
| 253 | args += " -k" |
| 254 | } else if mode != "cps" { |
| 255 | return fmt.Errorf("invalid mode %s; expected cps/rps", mode) |
| 256 | } |
Filip Tehlar | dda1f68 | 2023-04-24 17:52:50 +0200 | [diff] [blame] | 257 | // don't exit on socket receive errors |
| 258 | args += " -r" |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 259 | args += " http://" + serverAddress + ":80/64B.json" |
| 260 | abCont.extraRunningArgs = args |
| 261 | o, err := abCont.combinedOutput() |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 262 | rps := parseString(o, "Requests per second:") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 263 | s.log(rps) |
| 264 | s.log(err) |
adrianvillin | 7c67547 | 2024-02-12 02:44:53 -0500 | [diff] [blame] | 265 | s.assertNil(err, "err: '%s', output: '%s'", err, o) |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 266 | } else { |
| 267 | wrkCont := s.getContainerByName("wrk") |
Adrian Villin | 7ad37b5 | 2024-06-05 05:53:50 -0400 | [diff] [blame^] | 268 | wrkCont.runDetached = true |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 269 | args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients, |
| 270 | serverAddress) |
| 271 | wrkCont.extraRunningArgs = args |
| 272 | o, err := wrkCont.combinedOutput() |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 273 | rps := parseString(o, "requests") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 274 | s.log(rps) |
| 275 | s.log(err) |
adrianvillin | 7c67547 | 2024-02-12 02:44:53 -0500 | [diff] [blame] | 276 | s.assertNil(err, "err: '%s', output: '%s'", err, o) |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 277 | } |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 278 | return nil |
| 279 | } |
| 280 | |
Adrian Villin | 0df582e | 2024-05-22 09:26:47 -0400 | [diff] [blame] | 281 | // unstable with multiple workers |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 282 | func NginxPerfCpsTest(s *NoTopoSuite) { |
Adrian Villin | 0df582e | 2024-05-22 09:26:47 -0400 | [diff] [blame] | 283 | s.SkipIfMultiWorker() |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 284 | s.assertNil(runNginxPerf(s, "cps", "ab")) |
| 285 | } |
| 286 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 287 | func NginxPerfRpsTest(s *NoTopoSuite) { |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 288 | s.assertNil(runNginxPerf(s, "rps", "ab")) |
| 289 | } |
| 290 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 291 | func NginxPerfWrkTest(s *NoTopoSuite) { |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 292 | s.assertNil(runNginxPerf(s, "", "wrk")) |
| 293 | } |