From 1c9b694d3e91b502ca434a03a488ca1aaa8465e9 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Tue, 14 Oct 2025 04:04:43 -0400 Subject: [PATCH] http: add send get and close test Attempt to catch potential close/cleanup races with received data/request. Type: test Change-Id: Ic07b034272e11103669d8eb5a2fe56e1af3c0da7 Signed-off-by: Florin Coras Signed-off-by: Matus Fabian --- test-c/hs-test/http1_test.go | 21 ++++++++++++++++++++- test-c/hs-test/infra/utils.go | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/test-c/hs-test/http1_test.go b/test-c/hs-test/http1_test.go index 836177239fa..83063d0e737 100644 --- a/test-c/hs-test/http1_test.go +++ b/test-c/hs-test/http1_test.go @@ -38,7 +38,7 @@ func init() { HttpRequestLineTest, HttpClientGetTimeout, HttpStaticFileHandlerWrkTest, HttpStaticUrlHandlerWrkTest, HttpConnTimeoutTest, HttpClientGetRepeatTest, HttpClientPostRepeatTest, HttpIgnoreH2UpgradeTest, HttpInvalidAuthorityFormUriTest, HttpHeaderErrorConnectionDropTest, HttpClientInvalidHeaderNameTest, HttpStaticHttp1OnlyTest, HttpTimerSessionDisable, HttpClientBodySizeTest, - HttpStaticRedirectTest, HttpClientNoPrintTest, HttpClientChunkedDownloadTest, HttpClientPostRejectedTest) + HttpStaticRedirectTest, HttpClientNoPrintTest, HttpClientChunkedDownloadTest, HttpClientPostRejectedTest, HttpSendGetAndCloseTest) RegisterHttp1SoloTests(HttpStaticPromTest, HttpGetTpsTest, HttpGetTpsInterruptModeTest, PromConcurrentConnectionsTest, PromMemLeakTest, HttpClientPostMemLeakTest, HttpInvalidClientRequestMemLeakTest, HttpPostTpsTest, HttpPostTpsInterruptModeTest, PromConsecutiveConnectionsTest, HttpGetTpsTlsTest, HttpPostTpsTlsTest) @@ -1948,3 +1948,22 @@ func HttpIgnoreH2UpgradeTest(s *Http1Suite) { s.AssertHttpStatus(resp, 200) s.AssertHttpHeaderNotPresent(resp, "Upgrade") } + +func HttpSendGetAndCloseTest(s *Http1Suite) { + vpp := s.Containers.Vpp.VppInstance + serverAddress := s.VppAddr() + ":" + s.Ports.Http + + vpp.Container.Exec(false, "mkdir -p "+wwwRootPath) + content := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + err := vpp.Container.CreateFile(wwwRootPath+"/index.html", content) + s.AssertNil(err, fmt.Sprint(err)) + s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + " private-segment-size 256m")) + + err = TcpSendAndClose(serverAddress, "GET http://www.example.com/index.html HTTP/1.1\r\nHost: example.com\r\n\r\n") + s.AssertNil(err, fmt.Sprint(err)) + + // mostly to verify that vpp is still up + o := vpp.Vppctl("show session verbose proto http") + s.Log(o) + s.AssertNotContains(o, "established") +} diff --git a/test-c/hs-test/infra/utils.go b/test-c/hs-test/infra/utils.go index 3be32202673..41e328b08b4 100644 --- a/test-c/hs-test/infra/utils.go +++ b/test-c/hs-test/infra/utils.go @@ -144,6 +144,20 @@ func TcpSendReceive(address, data string) (string, error) { return string(reply), nil } +func TcpSendAndClose(address, data string) error { + conn, err := net.DialTimeout("tcp", address, time.Second*30) + if err != nil { + return err + } + defer conn.Close() + _, err = conn.Write([]byte(data)) + if err != nil { + return err + } + + return nil +} + /* RunCurlContainer execute curl command with given args. Container with name "curl" must be available. -- 2.16.6