diff options
Diffstat (limited to 'extras/hs-test/http_test.go')
-rw-r--r-- | extras/hs-test/http_test.go | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go index 733ca46934d..bfd2d34483c 100644 --- a/extras/hs-test/http_test.go +++ b/extras/hs-test/http_test.go @@ -6,6 +6,7 @@ import ( "github.com/onsi/gomega/ghttp" "github.com/onsi/gomega/gmeasure" "io" + "math/rand" "net" "net/http" "net/http/httptrace" @@ -30,8 +31,8 @@ func init() { HttpInvalidContentLengthTest, HttpInvalidTargetSyntaxTest, HttpStaticPathTraversalTest, HttpUriDecodeTest, HttpHeadersTest, HttpStaticFileHandlerTest, HttpStaticFileHandlerDefaultMaxAgeTest, HttpClientTest, HttpClientErrRespTest, HttpClientPostFormTest, HttpClientPostFileTest, HttpClientPostFilePtrTest, AuthorityFormTargetTest, HttpRequestLineTest) - RegisterNoTopoSoloTests(HttpStaticPromTest, HttpTpsTest, HttpTpsInterruptModeTest, PromConcurrentConnectionsTest, - PromMemLeakTest, HttpClientPostMemLeakTest, HttpInvalidClientRequestMemLeakTest) + RegisterNoTopoSoloTests(HttpStaticPromTest, HttpGetTpsTest, HttpGetTpsInterruptModeTest, PromConcurrentConnectionsTest, + PromMemLeakTest, HttpClientPostMemLeakTest, HttpInvalidClientRequestMemLeakTest, HttpPostTpsTest, HttpPostTpsInterruptModeTest) } const wwwRootPath = "/tmp/www_root" @@ -53,18 +54,51 @@ func httpDownloadBenchmark(s *HstSuite, experiment *gmeasure.Experiment, data in experiment.RecordValue("Download Speed", (float64(resp.ContentLength)/1024/1024)/duration.Seconds(), gmeasure.Units("MB/s"), gmeasure.Precision(2)) } -func HttpTpsInterruptModeTest(s *NoTopoSuite) { - HttpTpsTest(s) +func HttpGetTpsInterruptModeTest(s *NoTopoSuite) { + HttpGetTpsTest(s) } -func HttpTpsTest(s *NoTopoSuite) { +func HttpGetTpsTest(s *NoTopoSuite) { vpp := s.GetContainerByName("vpp").VppInstance serverAddress := s.VppAddr() url := "http://" + serverAddress + ":8080/test_file_10M" vpp.Vppctl("http tps uri tcp://0.0.0.0/8080") - s.RunBenchmark("HTTP tps 10M", 10, 0, httpDownloadBenchmark, url) + s.RunBenchmark("HTTP tps download 10M", 10, 0, httpDownloadBenchmark, url) +} + +func httpUploadBenchmark(s *HstSuite, experiment *gmeasure.Experiment, data interface{}) { + url, isValid := data.(string) + s.AssertEqual(true, isValid) + body := make([]byte, 10485760) + _, err := rand.Read(body) + client := NewHttpClient() + req, err := http.NewRequest("POST", url, bytes.NewBuffer(body)) + s.AssertNil(err, fmt.Sprint(err)) + t := time.Now() + resp, err := client.Do(req) + s.AssertNil(err, fmt.Sprint(err)) + defer resp.Body.Close() + s.AssertHttpStatus(resp, 200) + _, err = io.ReadAll(resp.Body) + s.AssertNil(err, fmt.Sprint(err)) + duration := time.Since(t) + experiment.RecordValue("Upload Speed", (float64(req.ContentLength)/1024/1024)/duration.Seconds(), gmeasure.Units("MB/s"), gmeasure.Precision(2)) +} + +func HttpPostTpsInterruptModeTest(s *NoTopoSuite) { + HttpPostTpsTest(s) +} + +func HttpPostTpsTest(s *NoTopoSuite) { + vpp := s.GetContainerByName("vpp").VppInstance + serverAddress := s.VppAddr() + url := "http://" + serverAddress + ":8080/test_file_10M" + + vpp.Vppctl("http tps uri tcp://0.0.0.0/8080") + + s.RunBenchmark("HTTP tps upload 10M", 10, 0, httpUploadBenchmark, url) } func HttpPersistentConnectionTest(s *NoTopoSuite) { |