poll on test start

This commit is contained in:
Tim Möhlmann 2023-04-26 19:54:47 +03:00
parent 234186c60c
commit 90ba3a8d92
5 changed files with 47 additions and 16 deletions

View File

@ -9,6 +9,7 @@ jobs:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
env: env:
DOCKER_BUILDKIT: 1 DOCKER_BUILDKIT: 1
INTEGRATION_DB_FLAVOR: ${{ matrix.db }}
steps: steps:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v3 uses: actions/setup-go@v3
@ -28,8 +29,10 @@ jobs:
- name: Download Go modules - name: Download Go modules
run: go mod download run: go mod download
- name: Start ${{ matrix.db }} database - name: Start ${{ matrix.db }} database
run: docker compose -f e2e/config/integration/docker-compose.yaml up --wait ${{ matrix.db }} run: docker compose -f e2e/config/integration/docker-compose.yaml up --wait ${INTEGRATION_DB_FLAVOR}
- name: Run integration test - name: Run zitadel init and setup
env: run: |
INTEGRATION_DB_FLAVOR: ${{ matrix.db }} go run main.go init --config internal/integration/config/zitadel.yaml --config internal/integration/config/${INTEGRATION_DB_FLAVOR}.yaml
go run main.go setup --masterkey MasterkeyNeedsToHave32Characters --config internal/integration/config/zitadel.yaml --config internal/integration/config/${INTEGRATION_DB_FLAVOR}.yaml
- name: Run integration tests
run: go test -tags=integration -parallel 1 -v ./internal/integration ./internal/api/grpc/... run: go test -tags=integration -parallel 1 -v ./internal/integration ./internal/api/grpc/...

View File

@ -89,7 +89,6 @@ Requirements:
} }
type Server struct { type Server struct {
background context.Context
Config *Config Config *Config
DB *database.DB DB *database.DB
KeyStorage crypto.KeyStorage KeyStorage crypto.KeyStorage
@ -203,7 +202,6 @@ func startZitadel(config *Config, masterKey string, server chan<- *Server) error
if server != nil { if server != nil {
server <- &Server{ server <- &Server{
background: ctx,
Config: config, Config: config,
DB: dbClient, DB: dbClient,
KeyStorage: keyStorage, KeyStorage: keyStorage,

View File

@ -22,7 +22,6 @@ func TestMain(m *testing.M) {
os.Exit(func() int { os.Exit(func() int {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel() defer cancel()
Tester = integration.NewTester(ctx) Tester = integration.NewTester(ctx)
defer Tester.Done() defer Tester.Done()
@ -31,7 +30,7 @@ func TestMain(m *testing.M) {
} }
func TestServer_Healthz(t *testing.T) { func TestServer_Healthz(t *testing.T) {
client := admin.NewAdminServiceClient(Tester.ClientConn) client := admin.NewAdminServiceClient(Tester.GRPCClientConn)
_, err := client.Healthz(context.TODO(), &admin.HealthzRequest{}) _, err := client.Healthz(context.TODO(), &admin.HealthzRequest{})
require.NoError(t, err) require.NoError(t, err)
} }

View File

@ -9,6 +9,7 @@ import (
"os" "os"
"strings" "strings"
"sync" "sync"
"time"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/zitadel/logging" "github.com/zitadel/logging"
@ -17,6 +18,7 @@ import (
"github.com/zitadel/zitadel/cmd" "github.com/zitadel/zitadel/cmd"
"github.com/zitadel/zitadel/cmd/start" "github.com/zitadel/zitadel/cmd/start"
"github.com/zitadel/zitadel/pkg/grpc/admin"
) )
var ( var (
@ -30,12 +32,11 @@ var (
type Tester struct { type Tester struct {
*start.Server *start.Server
ClientConn *grpc.ClientConn GRPCClientConn *grpc.ClientConn
wg sync.WaitGroup // used for shutdown
wg sync.WaitGroup // used for shutdown
} }
const commandLine = `start-from-init --masterkey MasterkeyNeedsToHave32Characters --tlsMode disabled` const commandLine = `start --masterkey MasterkeyNeedsToHave32Characters`
func (s *Tester) createClientConn(ctx context.Context) { func (s *Tester) createClientConn(ctx context.Context) {
target := fmt.Sprintf("localhost:%d", s.Config.Port) target := fmt.Sprintf("localhost:%d", s.Config.Port)
@ -49,11 +50,41 @@ func (s *Tester) createClientConn(ctx context.Context) {
logging.OnError(err).Fatal("integration tester client dial") logging.OnError(err).Fatal("integration tester client dial")
logging.New().WithField("target", target).Info("finished dialing grpc client conn") logging.New().WithField("target", target).Info("finished dialing grpc client conn")
s.ClientConn = cc s.GRPCClientConn = cc
err = s.pollHealth(ctx)
logging.OnError(err).Fatal("integration tester health")
}
// pollHealth waits until a healthy status is reported.
// TODO: remove when we make the setup blocking on all
// projections completed.
func (s *Tester) pollHealth(ctx context.Context) (err error) {
client := admin.NewAdminServiceClient(s.GRPCClientConn)
for {
err = func(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
_, err := client.Healthz(ctx, &admin.HealthzRequest{})
return err
}(ctx)
if err == nil {
return nil
}
logging.WithError(err).Info("poll healthz")
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(time.Second):
continue
}
}
} }
func (s *Tester) Done() { func (s *Tester) Done() {
err := s.ClientConn.Close() err := s.GRPCClientConn.Close()
logging.OnError(err).Error("integration tester client close") logging.OnError(err).Error("integration tester client close")
s.Shutdown <- os.Interrupt s.Shutdown <- os.Interrupt
@ -71,7 +102,7 @@ func NewTester(ctx context.Context) *Tester {
flavor := os.Getenv("INTEGRATION_DB_FLAVOR") flavor := os.Getenv("INTEGRATION_DB_FLAVOR")
switch flavor { switch flavor {
case "cockroach": case "cockroach", "":
err = viper.MergeConfig(bytes.NewBuffer(cockroachYAML)) err = viper.MergeConfig(bytes.NewBuffer(cockroachYAML))
case "postgres": case "postgres":
err = viper.MergeConfig(bytes.NewBuffer(postgresYAML)) err = viper.MergeConfig(bytes.NewBuffer(postgresYAML))

View File

@ -9,7 +9,7 @@ import (
) )
func TestNewTester(t *testing.T) { func TestNewTester(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel() defer cancel()
s := NewTester(ctx) s := NewTester(ctx)