Skip to content

Commit

Permalink
test: fix service port flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
eliobischof committed Apr 30, 2024
1 parent b4ddeec commit 67550c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 6 additions & 5 deletions charts/zitadel/acceptance/service_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
})
}
4 changes: 1 addition & 3 deletions charts/zitadel/acceptance/teardown.go
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

0 comments on commit 67550c1

Please sign in to comment.