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
env:
DOCKER_BUILDKIT: 1
INTEGRATION_DB_FLAVOR: ${{ matrix.db }}
steps:
- name: Set up Go
uses: actions/setup-go@v3
@ -28,8 +29,10 @@ jobs:
- name: Download Go modules
run: go mod download
- name: Start ${{ matrix.db }} database
run: docker compose -f e2e/config/integration/docker-compose.yaml up --wait ${{ matrix.db }}
- name: Run integration test
env:
INTEGRATION_DB_FLAVOR: ${{ matrix.db }}
run: docker compose -f e2e/config/integration/docker-compose.yaml up --wait ${INTEGRATION_DB_FLAVOR}
- name: Run zitadel init and setup
run: |
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/...

View File

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

View File

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

View File

@ -9,6 +9,7 @@ import (
"os"
"strings"
"sync"
"time"
"github.com/spf13/viper"
"github.com/zitadel/logging"
@ -17,6 +18,7 @@ import (
"github.com/zitadel/zitadel/cmd"
"github.com/zitadel/zitadel/cmd/start"
"github.com/zitadel/zitadel/pkg/grpc/admin"
)
var (
@ -30,12 +32,11 @@ var (
type Tester struct {
*start.Server
ClientConn *grpc.ClientConn
wg sync.WaitGroup // used for shutdown
GRPCClientConn *grpc.ClientConn
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) {
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.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() {
err := s.ClientConn.Close()
err := s.GRPCClientConn.Close()
logging.OnError(err).Error("integration tester client close")
s.Shutdown <- os.Interrupt
@ -71,7 +102,7 @@ func NewTester(ctx context.Context) *Tester {
flavor := os.Getenv("INTEGRATION_DB_FLAVOR")
switch flavor {
case "cockroach":
case "cockroach", "":
err = viper.MergeConfig(bytes.NewBuffer(cockroachYAML))
case "postgres":
err = viper.MergeConfig(bytes.NewBuffer(postgresYAML))

View File

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