Skip to content

Commit

Permalink
explcit conflict with kind test
Browse files Browse the repository at this point in the history
  • Loading branch information
nabuskey committed Oct 27, 2023
1 parent c6bb7ea commit 76abe71
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions pkg/controllers/gitserver/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ package gitserver
import (
"context"
"fmt"
"github.com/cnoe-io/idpbuilder/pkg/kind"
"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"
"github.com/cnoe-io/idpbuilder/pkg/docker"
"github.com/cnoe-io/idpbuilder/pkg/kind"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/go-connections/nat"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
controllerruntime "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -60,22 +59,6 @@ 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 All @@ -98,6 +81,25 @@ func TestReconcileGitServerImage(t *testing.T) {

defer dockerClient.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true})

waitTimeout := time.Second * 90
waitInterval := time.Second * 3
endTime := time.Now().Add(waitTimeout)
// avoid failures with the container that uses port 5001 in TestReconcileRegistry
for {
if time.Now().After(endTime) {
t.Fatalf("Timed out waiting for idpbuilder-testcase-registry container to terminate")
}
containers, _ := dockerClient.ContainerList(ctx, types.ContainerListOptions{
Filters: filters.NewArgs(filters.KeyValuePair{
Key: "reference",
Value: "idpbuilder-testcase-registry",
}),
})
if len(containers) == 0 {
break
}
time.Sleep(waitInterval)
}
err = dockerClient.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
if err != nil {
t.Fatalf("failed starting container %v", err)
Expand Down

0 comments on commit 76abe71

Please sign in to comment.