Skip to content

Commit

Permalink
test connection to first broker
Browse files Browse the repository at this point in the history
  • Loading branch information
lvrach committed Aug 16, 2024
1 parent a8ba282 commit 1fd6b1e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions testhelper/docker/resource/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package kafka
import (
_ "encoding/json"
"fmt"
"net"
"strconv"
"time"

_ "github.com/lib/pq"
"github.com/ory/dockertest/v3"
Expand Down Expand Up @@ -364,6 +366,18 @@ func Setup(pool *dockertest.Pool, cln resource.Cleaner, opts ...Option) (*Resour
}
res.Brokers = append(res.Brokers, containers[i].GetBoundIP(kafkaClientPort+"/tcp")+":"+containers[i].GetPort(kafkaClientPort+"/tcp"))
}
err = pool.Retry(func() error {
conn, err := net.DialTimeout("tcp", res.Brokers[0], time.Second)
if err != nil {
return err
}

return conn.Close()
})
if err != nil {
return nil, fmt.Errorf("could not connect to kafka: %w", err)
}

cln.Logf("Kafka brokers on %v", res.Brokers)

return res, nil
Expand Down

0 comments on commit 1fd6b1e

Please sign in to comment.