From 67550c163dec9ec0cb2bb41e55c066dd221861b2 Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Tue, 30 Apr 2024 09:19:01 +0200 Subject: [PATCH] test: fix service port flakiness --- charts/zitadel/acceptance/service_tunnel.go | 11 ++++++----- charts/zitadel/acceptance/teardown.go | 4 +--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/charts/zitadel/acceptance/service_tunnel.go b/charts/zitadel/acceptance/service_tunnel.go index e2a1eab0..6e656196 100644 --- a/charts/zitadel/acceptance/service_tunnel.go +++ b/charts/zitadel/acceptance/service_tunnel.go @@ -16,12 +16,11 @@ func (c CloseFunc) Close() { // ServiceTunnel must be closed using the returned close function func ServiceTunnel(cfg *ConfigurationTest) func() { serviceTunnel := k8s.NewTunnel(cfg.KubeOptions, k8s.ResourceTypeService, cfg.zitadelRelease, int(cfg.Port), 8080) - awaitServicePortToBeFree(cfg) - serviceTunnel.ForwardPort(cfg.T()) + awaitServicePortForward(cfg, serviceTunnel) return serviceTunnel.Close } -func awaitServicePortToBeFree(cfg *ConfigurationTest) { +func awaitServicePortForward(cfg *ConfigurationTest, tunnel *k8s.Tunnel) { t := cfg.T() addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", cfg.Port)) if err != nil { @@ -32,7 +31,9 @@ func awaitServicePortToBeFree(cfg *ConfigurationTest) { if err != nil { return err } - defer l.Close() - return nil + if err := l.Close(); err != nil { + panic(err) + } + return tunnel.ForwardPortE(cfg.T()) }) } diff --git a/charts/zitadel/acceptance/teardown.go b/charts/zitadel/acceptance/teardown.go index 14303d7b..f52981f5 100644 --- a/charts/zitadel/acceptance/teardown.go +++ b/charts/zitadel/acceptance/teardown.go @@ -1,8 +1,6 @@ package acceptance -import ( - "github.com/gruntwork-io/terratest/modules/k8s" -) +import "github.com/gruntwork-io/terratest/modules/k8s" func (s *ConfigurationTest) TearDownTest() { if !s.T().Failed() {