diff options
author | Adrian Villin <avillin@cisco.com> | 2024-11-04 13:16:24 +0100 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2024-11-21 07:52:58 +0000 |
commit | d74e440f2f2a441033a7f6fdf078670f125c41a8 (patch) | |
tree | 3566c44d58f0f4c7bd2a0d97d831d53ca3fcab7c /extras/hs-test/http_test.go | |
parent | 9cab992ff9aa0ab9b865ef2fff4ce7a633c54328 (diff) |
- added request repeating (repeat <count>|duration <seconds>)
- added basic stats
Type: feature
Change-Id: Ic69eac8029eac31ea5ace5b5c0da1ce7a3543ac0
Signed-off-by: Adrian Villin <avillin@cisco.com>
Diffstat (limited to 'extras/hs-test/http_test.go')
-rw-r--r-- | extras/hs-test/http_test.go | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go index 902d6efacfc..cdc52a1f76c 100644 --- a/extras/hs-test/http_test.go +++ b/extras/hs-test/http_test.go @@ -7,6 +7,7 @@ import ( "math/rand" "net" "net/http" + "net/http/httptest" "net/http/httptrace" "os" "strconv" @@ -34,7 +35,8 @@ func init() { HttpHeadersTest, HttpStaticFileHandlerTest, HttpStaticFileHandlerDefaultMaxAgeTest, HttpClientTest, HttpClientErrRespTest, HttpClientPostFormTest, HttpClientGet128kbResponseTest, HttpClientGetResponseBodyTest, HttpClientGetNoResponseBodyTest, HttpClientPostFileTest, HttpClientPostFilePtrTest, HttpUnitTest, - HttpRequestLineTest, HttpClientGetTimeout, HttpStaticFileHandlerWrkTest, HttpStaticUrlHandlerWrkTest, HttpConnTimeoutTest) + HttpRequestLineTest, HttpClientGetTimeout, HttpStaticFileHandlerWrkTest, HttpStaticUrlHandlerWrkTest, HttpConnTimeoutTest, + HttpClientGetRepeat, HttpClientPostRepeat) RegisterNoTopoSoloTests(HttpStaticPromTest, HttpGetTpsTest, HttpGetTpsInterruptModeTest, PromConcurrentConnectionsTest, PromMemLeakTest, HttpClientPostMemLeakTest, HttpInvalidClientRequestMemLeakTest, HttpPostTpsTest, HttpPostTpsInterruptModeTest, PromConsecutiveConnectionsTest) @@ -368,6 +370,80 @@ func httpClientGet(s *NoTopoSuite, response string, size int) { s.AssertContains(file_contents, response) } +func startSimpleServer(s *NoTopoSuite, replyCount *int, serverAddress string) (server *httptest.Server) { + var err error + server = httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello") + *replyCount++ + })) + server.Listener, err = net.Listen("tcp", serverAddress+":80") + s.AssertNil(err, "Error while creating listener.") + + server.Start() + + return server +} + +func HttpClientGetRepeat(s *NoTopoSuite) { + httpClientRepeat(s, "") +} + +func HttpClientPostRepeat(s *NoTopoSuite) { + httpClientRepeat(s, "post") +} + +func httpClientRepeat(s *NoTopoSuite, requestMethod string) { + replyCount := 0 + vpp := s.GetContainerByName("vpp").VppInstance + serverAddress := s.HostAddr() + repeatAmount := 10000 + server := startSimpleServer(s, &replyCount, serverAddress) + defer server.Close() + + if requestMethod == "post" { + fileName := "/tmp/test_file.txt" + s.Log(vpp.Container.Exec(false, "fallocate -l 64 "+fileName)) + s.Log(vpp.Container.Exec(false, "ls -la "+fileName)) + requestMethod += " file /tmp/test_file.txt" + } + + uri := "http://" + serverAddress + "/80" + cmd := fmt.Sprintf("http client %s use-ptr duration 10 header Hello:World uri %s target /index.html", + requestMethod, uri) + + s.Log("Duration 10s") + o := vpp.Vppctl(cmd) + outputLen := len(o) + if outputLen > 500 { + s.Log(o[:500]) + s.Log("* HST Framework: output limited to 500 chars to avoid flooding the console. Output length: " + fmt.Sprint(outputLen)) + } else { + s.Log(o) + } + s.Log("Server response count: %d", replyCount) + s.AssertNotNil(o) + s.AssertNotContains(o, "error") + s.AssertGreaterThan(replyCount, 15000) + + cmd = fmt.Sprintf("http client %s use-ptr repeat %d header Hello:World uri %s target /index.html", + requestMethod, repeatAmount, uri) + + replyCount = 0 + s.Log("Repeat %d", repeatAmount) + o = vpp.Vppctl(cmd) + outputLen = len(o) + if outputLen > 500 { + s.Log(o[:500]) + s.Log("* HST Framework: output limited to 500 chars to avoid flooding the console. Output length: " + fmt.Sprint(outputLen)) + } else { + s.Log(o) + } + s.Log("Server response count: %d", replyCount) + s.AssertNotNil(o) + s.AssertNotContains(o, "error") + s.AssertEqual(repeatAmount, replyCount) +} + func HttpClientGetTimeout(s *NoTopoSuite) { serverAddress := s.HostAddr() vpp := s.GetContainerByName("vpp").VppInstance |