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