diff options
Diffstat (limited to 'extras/hs-test/http_test.go')
-rw-r--r-- | extras/hs-test/http_test.go | 280 |
1 files changed, 216 insertions, 64 deletions
diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go index bfd2d34483c..902d6efacfc 100644 --- a/extras/hs-test/http_test.go +++ b/extras/hs-test/http_test.go @@ -3,8 +3,6 @@ package main import ( "bytes" "fmt" - "github.com/onsi/gomega/ghttp" - "github.com/onsi/gomega/gmeasure" "io" "math/rand" "net" @@ -12,9 +10,13 @@ import ( "net/http/httptrace" "os" "strconv" + "strings" "sync" "time" + "github.com/onsi/gomega/ghttp" + "github.com/onsi/gomega/gmeasure" + . "fd.io/hs-test/infra" . "github.com/onsi/ginkgo/v2" ) @@ -29,18 +31,22 @@ func init() { HttpContentLengthTest, HttpStaticBuildInUrlGetIfListTest, HttpStaticBuildInUrlGetVersionTest, HttpStaticMacTimeTest, HttpStaticBuildInUrlGetVersionVerboseTest, HttpVersionNotSupportedTest, HttpInvalidContentLengthTest, HttpInvalidTargetSyntaxTest, HttpStaticPathTraversalTest, HttpUriDecodeTest, - HttpHeadersTest, HttpStaticFileHandlerTest, HttpStaticFileHandlerDefaultMaxAgeTest, HttpClientTest, HttpClientErrRespTest, HttpClientPostFormTest, - HttpClientPostFileTest, HttpClientPostFilePtrTest, AuthorityFormTargetTest, HttpRequestLineTest) + HttpHeadersTest, HttpStaticFileHandlerTest, HttpStaticFileHandlerDefaultMaxAgeTest, HttpClientTest, + HttpClientErrRespTest, HttpClientPostFormTest, HttpClientGet128kbResponseTest, HttpClientGetResponseBodyTest, + HttpClientGetNoResponseBodyTest, HttpClientPostFileTest, HttpClientPostFilePtrTest, HttpUnitTest, + HttpRequestLineTest, HttpClientGetTimeout, HttpStaticFileHandlerWrkTest, HttpStaticUrlHandlerWrkTest, HttpConnTimeoutTest) RegisterNoTopoSoloTests(HttpStaticPromTest, HttpGetTpsTest, HttpGetTpsInterruptModeTest, PromConcurrentConnectionsTest, - PromMemLeakTest, HttpClientPostMemLeakTest, HttpInvalidClientRequestMemLeakTest, HttpPostTpsTest, HttpPostTpsInterruptModeTest) + PromMemLeakTest, HttpClientPostMemLeakTest, HttpInvalidClientRequestMemLeakTest, HttpPostTpsTest, HttpPostTpsInterruptModeTest, + PromConsecutiveConnectionsTest) } const wwwRootPath = "/tmp/www_root" +const defaultHttpTimeout = time.Second * 10 func httpDownloadBenchmark(s *HstSuite, experiment *gmeasure.Experiment, data interface{}) { url, isValid := data.(string) s.AssertEqual(true, isValid) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", url, nil) s.AssertNil(err, fmt.Sprint(err)) t := time.Now() @@ -73,7 +79,7 @@ func httpUploadBenchmark(s *HstSuite, experiment *gmeasure.Experiment, data inte s.AssertEqual(true, isValid) body := make([]byte, 10485760) _, err := rand.Read(body) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("POST", url, bytes.NewBuffer(body)) s.AssertNil(err, fmt.Sprint(err)) t := time.Now() @@ -130,7 +136,7 @@ func HttpPersistentConnectionTest(s *NoTopoSuite) { s.AssertHttpContentLength(resp, int64(0)) o1 := vpp.Vppctl("show session verbose proto http state ready") s.Log(o1) - s.AssertContains(o1, "ESTABLISHED") + s.AssertContains(o1, "established") req, err = http.NewRequest("GET", "http://"+serverAddress+":80/test1", nil) s.AssertNil(err, fmt.Sprint(err)) @@ -148,7 +154,7 @@ func HttpPersistentConnectionTest(s *NoTopoSuite) { s.AssertHttpBody(resp, "hello") o2 := vpp.Vppctl("show session verbose proto http state ready") s.Log(o2) - s.AssertContains(o2, "ESTABLISHED") + s.AssertContains(o2, "established") s.AssertEqual(o1, o2) req, err = http.NewRequest("GET", "http://"+serverAddress+":80/test2", nil) @@ -162,9 +168,8 @@ func HttpPersistentConnectionTest(s *NoTopoSuite) { s.AssertHttpBody(resp, "some data") o2 = vpp.Vppctl("show session verbose proto http state ready") s.Log(o2) - s.AssertContains(o2, "ESTABLISHED") + s.AssertContains(o2, "established") s.AssertEqual(o1, o2) - } func HttpPipeliningTest(s *NoTopoSuite) { @@ -192,7 +197,7 @@ func HttpPipeliningTest(s *NoTopoSuite) { s.AssertNil(err, fmt.Sprint(err)) s.AssertEqual(n, len([]rune(req2))) reply := make([]byte, 1024) - n, err = conn.Read(reply) + _, err = conn.Read(reply) s.AssertNil(err, fmt.Sprint(err)) s.Log(string(reply)) s.AssertContains(string(reply), "delayed data", "first request response not received") @@ -293,6 +298,7 @@ func HttpClientPostFormTest(s *NoTopoSuite) { s.LogHttpReq(true), ghttp.VerifyRequest("POST", "/test"), ghttp.VerifyContentType("application/x-www-form-urlencoded"), + ghttp.VerifyHeaderKV("Hello", "World"), ghttp.VerifyBody([]byte(body)), ghttp.RespondWith(http.StatusOK, nil), )) @@ -301,18 +307,100 @@ func HttpClientPostFormTest(s *NoTopoSuite) { uri := "http://" + serverAddress + "/80" vpp := s.GetContainerByName("vpp").VppInstance - o := vpp.Vppctl("http post uri " + uri + " target /test data " + body) + o := vpp.Vppctl("http client post verbose header Hello:World uri " + uri + " target /test data " + body) s.Log(o) - s.AssertNotContains(o, "error") + s.AssertContains(o, "200 OK") +} + +func HttpClientGetResponseBodyTest(s *NoTopoSuite) { + response := "<body>hello world</body>" + size := len(response) + httpClientGet(s, response, size) +} + +func HttpClientGet128kbResponseTest(s *NoTopoSuite) { + response := strings.Repeat("a", 128*1024) + size := len(response) + httpClientGet(s, response, size) +} + +func HttpClientGetNoResponseBodyTest(s *NoTopoSuite) { + response := "" + httpClientGet(s, response, 0) +} + +func httpClientGet(s *NoTopoSuite, response string, size int) { + serverAddress := s.HostAddr() + vpp := s.GetContainerByName("vpp").VppInstance + + server := ghttp.NewUnstartedServer() + l, err := net.Listen("tcp", serverAddress+":80") + s.AssertNil(err, fmt.Sprint(err)) + server.HTTPTestServer.Listener = l + server.AppendHandlers( + ghttp.CombineHandlers( + s.LogHttpReq(false), + ghttp.VerifyRequest("GET", "/test"), + ghttp.VerifyHeaderKV("Hello", "World"), + ghttp.VerifyHeaderKV("Test-H2", "Test-K2"), + ghttp.RespondWith(http.StatusOK, string(response), http.Header{"Content-Length": {strconv.Itoa(size)}}), + )) + server.Start() + defer server.Close() + + uri := "http://" + serverAddress + "/80" + cmd := "http client use-ptr verbose header Hello:World header Test-H2:Test-K2 save-to response.txt uri " + uri + " target /test" + + 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.AssertContains(o, "200 OK") + s.AssertContains(o, response) + s.AssertContains(o, "Content-Length: "+strconv.Itoa(size)) + + file_contents := vpp.Container.Exec(false, "cat /tmp/response.txt") + s.AssertContains(file_contents, response) +} + +func HttpClientGetTimeout(s *NoTopoSuite) { + serverAddress := s.HostAddr() + vpp := s.GetContainerByName("vpp").VppInstance + + server := ghttp.NewUnstartedServer() + l, err := net.Listen("tcp", serverAddress+":"+s.GetPortFromPpid()) + s.AssertNil(err, fmt.Sprint(err)) + server.HTTPTestServer.Listener = l + server.AppendHandlers( + ghttp.CombineHandlers( + s.LogHttpReq(false), + ghttp.VerifyRequest("GET", "/timeout"), + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + time.Sleep(5 * time.Second) + }), + ghttp.RespondWith(http.StatusOK, nil), + )) + server.Start() + defer server.Close() + uri := "http://" + serverAddress + "/" + s.GetPortFromPpid() + cmd := "http client verbose timeout 1 uri " + uri + " target /timeout" + + o := vpp.Vppctl(cmd) + s.Log(o) + s.AssertContains(o, "error: timeout") } func httpClientPostFile(s *NoTopoSuite, usePtr bool, fileSize int) { serverAddress := s.HostAddr() vpp := s.GetContainerByName("vpp").VppInstance fileName := "/tmp/test_file.txt" - s.Log(vpp.Container.Exec("fallocate -l " + strconv.Itoa(fileSize) + " " + fileName)) - s.Log(vpp.Container.Exec("ls -la " + fileName)) + s.Log(vpp.Container.Exec(false, "fallocate -l "+strconv.Itoa(fileSize)+" "+fileName)) + s.Log(vpp.Container.Exec(false, "ls -la "+fileName)) server := ghttp.NewUnstartedServer() l, err := net.Listen("tcp", serverAddress+":80") @@ -330,14 +418,14 @@ func httpClientPostFile(s *NoTopoSuite, usePtr bool, fileSize int) { defer server.Close() uri := "http://" + serverAddress + "/80" - cmd := "http post uri " + uri + " target /test file " + fileName + cmd := "http client post verbose uri " + uri + " target /test file " + fileName if usePtr { cmd += " use-ptr" } o := vpp.Vppctl(cmd) s.Log(o) - s.AssertNotContains(o, "error") + s.AssertContains(o, "200 OK") } func HttpClientPostFileTest(s *NoTopoSuite) { @@ -348,24 +436,11 @@ func HttpClientPostFilePtrTest(s *NoTopoSuite) { httpClientPostFile(s, true, 131072) } -func cliTestAuthority(s *NoTopoSuite, authority string) { - o := s.GetContainerByName("vpp").VppInstance.Vppctl("test http authority-form " + authority) - s.AssertNotContains(o, "error") - s.AssertContains(o, authority) -} - -func cliTestAuthorityError(s *NoTopoSuite, authority string) { - o := s.GetContainerByName("vpp").VppInstance.Vppctl("test http authority-form " + authority) - s.AssertContains(o, "error") -} - -func AuthorityFormTargetTest(s *NoTopoSuite) { - cliTestAuthority(s, "10.10.2.45:20") - cliTestAuthority(s, "[dead:beef::1234]:443") - cliTestAuthorityError(s, "example.com:80") - cliTestAuthorityError(s, "10.10.2.45") - cliTestAuthorityError(s, "1000.10.2.45:20") - cliTestAuthorityError(s, "[xyz0::1234]:443") +func HttpUnitTest(s *NoTopoSuite) { + vpp := s.GetContainerByName("vpp").VppInstance + o := vpp.Vppctl("test http all") + s.Log(o) + s.AssertNotContains(o, "FAIL") } func HttpStaticPromTest(s *NoTopoSuite) { @@ -375,7 +450,7 @@ func HttpStaticPromTest(s *NoTopoSuite) { s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers")) s.Log(vpp.Vppctl("prom enable")) time.Sleep(time.Second * 5) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80/"+query, nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -389,8 +464,8 @@ func HttpStaticPromTest(s *NoTopoSuite) { s.AssertNil(err, fmt.Sprint(err)) } -func promReq(s *NoTopoSuite, url string) { - client := NewHttpClient() +func promReq(s *NoTopoSuite, url string, timeout time.Duration) { + client := NewHttpClient(timeout) req, err := http.NewRequest("GET", url, nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -404,7 +479,7 @@ func promReq(s *NoTopoSuite, url string) { func promReqWg(s *NoTopoSuite, url string, wg *sync.WaitGroup) { defer GinkgoRecover() defer wg.Done() - promReq(s, url) + promReq(s, url, defaultHttpTimeout) } func PromConcurrentConnectionsTest(s *NoTopoSuite) { @@ -425,6 +500,20 @@ func PromConcurrentConnectionsTest(s *NoTopoSuite) { s.Log(vpp.Vppctl("show session verbose proto http")) } +func PromConsecutiveConnectionsTest(s *NoTopoSuite) { + vpp := s.GetContainerByName("vpp").VppInstance + serverAddress := s.VppAddr() + url := "http://" + serverAddress + ":80/stats.prom" + + s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers")) + s.Log(vpp.Vppctl("prom enable")) + time.Sleep(time.Second * 5) + + for i := 0; i < 1000; i++ { + promReq(s, url, time.Millisecond*500) + } +} + func PromMemLeakTest(s *NoTopoSuite) { s.SkipUnlessLeakCheck() @@ -440,7 +529,7 @@ func PromMemLeakTest(s *NoTopoSuite) { time.Sleep(time.Second * 3) /* warmup request (FIB) */ - promReq(s, url) + promReq(s, url, defaultHttpTimeout) vpp.EnableMemoryTrace() traces1, err := vpp.GetMemoryTrace() @@ -449,7 +538,7 @@ func PromMemLeakTest(s *NoTopoSuite) { /* collect stats couple of times */ for i := 0; i < 5; i++ { time.Sleep(time.Second * 1) - promReq(s, url) + promReq(s, url, defaultHttpTimeout) } /* let's give it some time to clean up sessions */ @@ -577,6 +666,39 @@ func HttpInvalidClientRequestMemLeakTest(s *NoTopoSuite) { } +func runWrkPerf(s *NoTopoSuite) { + nConnections := 1000 + serverAddress := s.VppAddr() + + wrkCont := s.GetContainerByName("wrk") + args := fmt.Sprintf("-c %d -t 2 -d 30s http://%s:80/64B", nConnections, serverAddress) + wrkCont.ExtraRunningArgs = args + wrkCont.Run() + s.Log("Please wait for 30s, test is running.") + o, err := wrkCont.GetOutput() + s.Log(o) + s.AssertEmpty(err, "err: '%s'", err) +} + +func HttpStaticFileHandlerWrkTest(s *NoTopoSuite) { + vpp := s.GetContainerByName("vpp").VppInstance + serverAddress := s.VppAddr() + vpp.Container.Exec(false, "mkdir -p "+wwwRootPath) + content := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + err := vpp.Container.CreateFile(wwwRootPath+"/64B", content) + s.AssertNil(err, fmt.Sprint(err)) + s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 private-segment-size 256m")) + runWrkPerf(s) +} + +func HttpStaticUrlHandlerWrkTest(s *NoTopoSuite) { + vpp := s.GetContainerByName("vpp").VppInstance + serverAddress := s.VppAddr() + s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers private-segment-size 256m")) + s.Log(vpp.Vppctl("test-url-handler enable")) + runWrkPerf(s) +} + func HttpStaticFileHandlerDefaultMaxAgeTest(s *NoTopoSuite) { HttpStaticFileHandlerTestFunction(s, "default") } @@ -598,7 +720,7 @@ func HttpStaticFileHandlerTestFunction(s *NoTopoSuite, max_age string) { content2 := "<html><body><p>Page</p></body></html>" vpp := s.GetContainerByName("vpp").VppInstance - vpp.Container.Exec("mkdir -p " + wwwRootPath) + vpp.Container.Exec(false, "mkdir -p "+wwwRootPath) err := vpp.Container.CreateFile(wwwRootPath+"/index.html", content) s.AssertNil(err, fmt.Sprint(err)) err = vpp.Container.CreateFile(wwwRootPath+"/page.html", content2) @@ -606,7 +728,7 @@ func HttpStaticFileHandlerTestFunction(s *NoTopoSuite, max_age string) { serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug cache-size 2m " + maxAgeFormatted)) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80/index.html", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -654,14 +776,14 @@ func HttpStaticFileHandlerTestFunction(s *NoTopoSuite, max_age string) { func HttpStaticPathTraversalTest(s *NoTopoSuite) { vpp := s.GetContainerByName("vpp").VppInstance - vpp.Container.Exec("mkdir -p " + wwwRootPath) - vpp.Container.Exec("mkdir -p " + "/tmp/secret_folder") + vpp.Container.Exec(false, "mkdir -p "+wwwRootPath) + vpp.Container.Exec(false, "mkdir -p "+"/tmp/secret_folder") err := vpp.Container.CreateFile("/tmp/secret_folder/secret_file.txt", "secret") s.AssertNil(err, fmt.Sprint(err)) serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug")) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80/../secret_folder/secret_file.txt", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -676,13 +798,13 @@ func HttpStaticPathTraversalTest(s *NoTopoSuite) { func HttpStaticMovedTest(s *NoTopoSuite) { vpp := s.GetContainerByName("vpp").VppInstance - vpp.Container.Exec("mkdir -p " + wwwRootPath + "/tmp.aaa") + vpp.Container.Exec(false, "mkdir -p "+wwwRootPath+"/tmp.aaa") err := vpp.Container.CreateFile(wwwRootPath+"/tmp.aaa/index.html", "<html><body><p>Hello</p></body></html>") s.AssertNil(err, fmt.Sprint(err)) serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug")) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80/tmp.aaa", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -698,11 +820,11 @@ func HttpStaticMovedTest(s *NoTopoSuite) { func HttpStaticNotFoundTest(s *NoTopoSuite) { vpp := s.GetContainerByName("vpp").VppInstance - vpp.Container.Exec("mkdir -p " + wwwRootPath) + vpp.Container.Exec(false, "mkdir -p "+wwwRootPath) serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug")) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80/notfound.html", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -720,7 +842,7 @@ func HttpCliMethodNotAllowedTest(s *NoTopoSuite) { serverAddress := s.VppAddr() vpp.Vppctl("http cli server") - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("POST", "http://"+serverAddress+":80/test", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -738,7 +860,7 @@ func HttpCliBadRequestTest(s *NoTopoSuite) { serverAddress := s.VppAddr() vpp.Vppctl("http cli server") - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -753,10 +875,10 @@ func HttpCliBadRequestTest(s *NoTopoSuite) { func HttpStaticBuildInUrlGetVersionTest(s *NoTopoSuite) { vpp := s.GetContainerByName("vpp").VppInstance serverAddress := s.VppAddr() - s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) + s.Log(vpp.Vppctl("http static server uri tls://" + serverAddress + "/80 url-handlers debug")) - client := NewHttpClient() - req, err := http.NewRequest("GET", "http://"+serverAddress+":80/version.json", nil) + client := NewHttpClient(defaultHttpTimeout) + req, err := http.NewRequest("GET", "https://"+serverAddress+":80/version.json", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) s.AssertNil(err, fmt.Sprint(err)) @@ -779,7 +901,7 @@ func HttpStaticBuildInUrlGetVersionVerboseTest(s *NoTopoSuite) { serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80/version.json?verbose=true", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -803,7 +925,7 @@ func HttpStaticBuildInUrlGetIfListTest(s *NoTopoSuite) { serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80/interface_list.json", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -823,7 +945,7 @@ func HttpStaticBuildInUrlGetIfStatsTest(s *NoTopoSuite) { serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80/interface_stats.json", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -852,7 +974,7 @@ func HttpStaticBuildInUrlPostIfStatsTest(s *NoTopoSuite) { s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) body := []byte(s.VppIfName()) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("POST", "http://"+serverAddress+":80/interface_stats.json", bytes.NewBuffer(body)) s.AssertNil(err, fmt.Sprint(err)) @@ -873,7 +995,7 @@ func HttpStaticMacTimeTest(s *NoTopoSuite) { s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) s.Log(vpp.Vppctl("mactime enable-disable " + s.VppIfName())) - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80/mactime.json", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -1044,7 +1166,7 @@ func HttpMethodNotImplementedTest(s *NoTopoSuite) { serverAddress := s.VppAddr() vpp.Vppctl("http cli server") - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("OPTIONS", "http://"+serverAddress+":80/show/version", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -1071,7 +1193,7 @@ func HttpUriDecodeTest(s *NoTopoSuite) { serverAddress := s.VppAddr() vpp.Vppctl("http cli server") - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80/sh%6fw%20versio%6E%20verbose", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -1143,7 +1265,7 @@ func HeaderServerTest(s *NoTopoSuite) { serverAddress := s.VppAddr() vpp.Vppctl("http cli server") - client := NewHttpClient() + client := NewHttpClient(defaultHttpTimeout) req, err := http.NewRequest("GET", "http://"+serverAddress+":80/show/version", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) @@ -1154,3 +1276,33 @@ func HeaderServerTest(s *NoTopoSuite) { s.AssertHttpHeaderWithValue(resp, "Server", "http_cli_server") s.AssertHttpHeaderWithValue(resp, "Content-Type", "text/html") } + +func HttpConnTimeoutTest(s *NoTopoSuite) { + vpp := s.GetContainerByName("vpp").VppInstance + serverAddress := s.VppAddr() + s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug keepalive-timeout 2")) + + req := "GET /version.json HTTP/1.1\r\nHost:" + serverAddress + ":80\r\nUser-Agent:test\r\n\r\n" + conn, err := net.DialTimeout("tcp", serverAddress+":80", time.Second*30) + s.AssertNil(err, fmt.Sprint(err)) + defer conn.Close() + err = conn.SetDeadline(time.Now().Add(time.Second * 30)) + s.AssertNil(err, fmt.Sprint(err)) + _, err = conn.Write([]byte(req)) + s.AssertNil(err, fmt.Sprint(err)) + reply := make([]byte, 1024) + _, err = conn.Read(reply) + s.AssertNil(err, fmt.Sprint(err)) + s.AssertContains(string(reply), "HTTP/1.1 200 OK") + s.Log(vpp.Vppctl("show session verbose 2")) + + s.Log("waiting for close on the server side") + time.Sleep(time.Second * 5) + s.Log(vpp.Vppctl("show session verbose 2")) + + _, err = conn.Write([]byte(req)) + s.AssertNil(err, fmt.Sprint(err)) + reply = make([]byte, 1024) + _, err = conn.Read(reply) + s.AssertMatchError(err, io.EOF, "connection not closed by server") +} |