Skip to content

Commit

Permalink
add tcp connection check
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu Mccloskey <[email protected]>
  • Loading branch information
nabuskey committed Oct 26, 2023
1 parent a79b6ec commit c14e767
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/controllers/gitserver/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"io"
"net"
"os"
"strconv"
"strings"
"testing"
"time"

"github.com/cnoe-io/idpbuilder/api/v1alpha1"
"github.com/cnoe-io/idpbuilder/pkg/apps"
Expand Down Expand Up @@ -57,6 +60,22 @@ func TestReconcileGitServerImage(t *testing.T) {
t.Fatalf("failed pulilng registry image: %v", err)
}

waitTimeout := time.Second * 90
waitInterval := time.Second * 3
// very crude. no guarantee that the port will be available by the time request is sent to docker
endTime := time.Now().Add(waitTimeout)
for {
if time.Now().After(endTime) {
t.Fatalf("Timed out waiting for port %d to be available", kind.ExposedRegistryPort)
}
conn, cErr := net.DialTimeout("tcp", net.JoinHostPort("0.0.0.0", strconv.Itoa(int(kind.ExposedRegistryPort))), time.Second*3)
if cErr != nil {
break
}
conn.Close()
time.Sleep(waitInterval)
}

resp, err := dockerClient.ContainerCreate(ctx, &container.Config{
Image: "docker.io/library/registry:2",
Tty: false,
Expand Down Expand Up @@ -98,3 +117,4 @@ func TestReconcileGitServerImage(t *testing.T) {
t.Errorf("Removing docker image: %v", err)
}
}

0 comments on commit c14e767

Please sign in to comment.