From 7af03a0d880ed9d5a09e633e779f7abd72e6fdc2 Mon Sep 17 00:00:00 2001 From: Adrian Villin Date: Mon, 2 Jun 2025 16:53:41 +0200 Subject: [PATCH] hs-test: improve teardown reliability - added defer to some teardown functions - framework now recovers when Vppctl() is used before vppinstance is created Type: test Change-Id: Ia37cca0ef24f8936cbf350636e249efbf78b13ec Signed-off-by: Adrian Villin --- extras/hs-test/infra/suite_cpu_pinning.go | 3 +-- extras/hs-test/infra/suite_envoy_proxy.go | 2 +- extras/hs-test/infra/suite_ldp.go | 3 +-- extras/hs-test/infra/suite_nginx_proxy.go | 2 +- extras/hs-test/infra/suite_no_topo.go | 2 +- extras/hs-test/infra/suite_no_topo6.go | 2 +- extras/hs-test/infra/suite_vpp_proxy.go | 2 +- extras/hs-test/infra/suite_vpp_udp_proxy.go | 2 +- extras/hs-test/infra/vppinstance.go | 8 ++++++++ 9 files changed, 16 insertions(+), 10 deletions(-) diff --git a/extras/hs-test/infra/suite_cpu_pinning.go b/extras/hs-test/infra/suite_cpu_pinning.go index 6808768d49c..e80682dcb2f 100644 --- a/extras/hs-test/infra/suite_cpu_pinning.go +++ b/extras/hs-test/infra/suite_cpu_pinning.go @@ -58,11 +58,10 @@ func (s *CpuPinningSuite) SetupTest() { } func (s *CpuPinningSuite) TeardownTest() { + defer s.HstSuite.TeardownTest() // reset vars s.CpuCount = *NConfiguredCpus s.CpuAllocator.maxContainerCount = s.previousMaxContainerCount - s.HstSuite.TeardownTest() - } var _ = Describe("CpuPinningSuite", Ordered, ContinueOnFailure, func() { diff --git a/extras/hs-test/infra/suite_envoy_proxy.go b/extras/hs-test/infra/suite_envoy_proxy.go index 7119b0ff1d9..2d184270b84 100644 --- a/extras/hs-test/infra/suite_envoy_proxy.go +++ b/extras/hs-test/infra/suite_envoy_proxy.go @@ -151,11 +151,11 @@ func (s *EnvoyProxySuite) SetupTest() { } func (s *EnvoyProxySuite) TeardownTest() { + defer s.HstSuite.TeardownTest() if CurrentSpecReport().Failed() { s.CollectNginxLogs(s.Containers.NginxServerTransient) s.CollectEnvoyLogs(s.Containers.EnvoyProxy) } - s.HstSuite.TeardownTest() } func (s *EnvoyProxySuite) ProxyAddr() string { diff --git a/extras/hs-test/infra/suite_ldp.go b/extras/hs-test/infra/suite_ldp.go index 0baeacd505a..78c9e14892e 100644 --- a/extras/hs-test/infra/suite_ldp.go +++ b/extras/hs-test/infra/suite_ldp.go @@ -100,6 +100,7 @@ func (s *LdpSuite) SetupTest() { } func (s *LdpSuite) TeardownTest() { + defer s.HstSuite.TeardownTest() if CurrentSpecReport().Failed() { s.CollectIperfLogs(s.Containers.ServerApp) s.CollectRedisServerLogs(s.Containers.ServerApp) @@ -111,8 +112,6 @@ func (s *LdpSuite) TeardownTest() { delete(container.EnvVars, "LD_PRELOAD") delete(container.EnvVars, "VCL_CONFIG") } - s.HstSuite.TeardownTest() - } func (s *LdpSuite) CreateVclConfig(container *Container) { diff --git a/extras/hs-test/infra/suite_nginx_proxy.go b/extras/hs-test/infra/suite_nginx_proxy.go index 8006e6fd4d7..05b0960eedb 100644 --- a/extras/hs-test/infra/suite_nginx_proxy.go +++ b/extras/hs-test/infra/suite_nginx_proxy.go @@ -117,11 +117,11 @@ func (s *NginxProxySuite) SetupTest() { } func (s *NginxProxySuite) TeardownTest() { + defer s.HstSuite.TeardownTest() if CurrentSpecReport().Failed() { s.CollectNginxLogs(s.Containers.NginxProxy) s.CollectNginxLogs(s.Containers.NginxServerTransient) } - s.HstSuite.TeardownTest() } func (s *NginxProxySuite) CreateNginxProxyConfig(container *Container, multiThreadWorkers bool) { diff --git a/extras/hs-test/infra/suite_no_topo.go b/extras/hs-test/infra/suite_no_topo.go index 2d96ac9cd2d..e464ef7f95d 100644 --- a/extras/hs-test/infra/suite_no_topo.go +++ b/extras/hs-test/infra/suite_no_topo.go @@ -87,10 +87,10 @@ func (s *NoTopoSuite) SetupTest() { } func (s *NoTopoSuite) TeardownTest() { + defer s.HstSuite.TeardownTest() if CurrentSpecReport().Failed() { s.CollectNginxLogs(s.Containers.NginxHttp3) } - s.HstSuite.TeardownTest() } func (s *NoTopoSuite) CreateNginxConfig(container *Container, multiThreadWorkers bool) { diff --git a/extras/hs-test/infra/suite_no_topo6.go b/extras/hs-test/infra/suite_no_topo6.go index 8b67791597f..1b21469d1a6 100644 --- a/extras/hs-test/infra/suite_no_topo6.go +++ b/extras/hs-test/infra/suite_no_topo6.go @@ -85,10 +85,10 @@ func (s *NoTopo6Suite) SetupTest() { } func (s *NoTopo6Suite) TeardownTest() { + defer s.HstSuite.TeardownTest() if CurrentSpecReport().Failed() { s.CollectNginxLogs(s.Containers.NginxHttp3) } - s.HstSuite.TeardownTest() } func (s *NoTopo6Suite) CreateNginxConfig(container *Container, multiThreadWorkers bool) { diff --git a/extras/hs-test/infra/suite_vpp_proxy.go b/extras/hs-test/infra/suite_vpp_proxy.go index 92ca24c9d9e..2226358c770 100644 --- a/extras/hs-test/infra/suite_vpp_proxy.go +++ b/extras/hs-test/infra/suite_vpp_proxy.go @@ -93,6 +93,7 @@ func (s *VppProxySuite) SetupTest() { } func (s *VppProxySuite) TeardownTest() { + defer s.HstSuite.TeardownTest() vpp := s.Containers.VppProxy.VppInstance if CurrentSpecReport().Failed() { s.Log(vpp.Vppctl("show session verbose 2")) @@ -100,7 +101,6 @@ func (s *VppProxySuite) TeardownTest() { s.CollectNginxLogs(s.Containers.NginxServerTransient) s.CollectIperfLogs(s.Containers.IperfS) } - s.HstSuite.TeardownTest() } func (s *VppProxySuite) SetupNginxServer() { diff --git a/extras/hs-test/infra/suite_vpp_udp_proxy.go b/extras/hs-test/infra/suite_vpp_udp_proxy.go index d6f58ac86cc..aad821fad12 100644 --- a/extras/hs-test/infra/suite_vpp_udp_proxy.go +++ b/extras/hs-test/infra/suite_vpp_udp_proxy.go @@ -88,12 +88,12 @@ func (s *VppUdpProxySuite) SetupTest() { } func (s *VppUdpProxySuite) TeardownTest() { + defer s.HstSuite.TeardownTest() vpp := s.Containers.VppProxy.VppInstance if CurrentSpecReport().Failed() { s.Log(vpp.Vppctl("show session verbose 2")) s.Log(vpp.Vppctl("show error")) } - s.HstSuite.TeardownTest() } func (s *VppUdpProxySuite) VppProxyAddr() string { diff --git a/extras/hs-test/infra/vppinstance.go b/extras/hs-test/infra/vppinstance.go index 501eb417c65..ec32f85bc41 100644 --- a/extras/hs-test/infra/vppinstance.go +++ b/extras/hs-test/infra/vppinstance.go @@ -258,6 +258,14 @@ func (vpp *VppInstance) Stop() { } func (vpp *VppInstance) Vppctl(command string, arguments ...any) string { + defer func() { + if r := recover(); r != nil { + fmt.Printf("\n*******************************************************************************\n"+ + "[%v]\nyou probably used Vppctl() without creating a vppinstance first or used Vppctl() on the wrong container\n"+ + "*******************************************************************************\n", r) + } + }() + vppCliCommand := fmt.Sprintf(command, arguments...) containerExecCommand := fmt.Sprintf("docker exec --detach=false %[1]s vppctl -s %[2]s %[3]s", vpp.Container.Name, vpp.getCliSocket(), vppCliCommand) -- 2.16.6