Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v17] Reduce TestInitDatabaseService flakiness #50086

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/jonboulle/clockwork"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
Expand Down Expand Up @@ -1816,19 +1817,28 @@ func TestInitDatabaseService(t *testing.T) {
cfg.Databases.Enabled = test.enabled
cfg.Databases.Databases = test.databases

// This timeout should consider time to receive the event + shutdown
// time.
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

var eg errgroup.Group
process, err := NewTeleport(cfg)
require.NoError(t, err)
require.NoError(t, process.Start())
eg.Go(func() error { return process.WaitForSignals(ctx, nil) })
// Ensures the process is closed in failure scenarios.
t.Cleanup(func() {
require.NoError(t, process.Close())
cancel()
_ = eg.Wait()
})
require.NoError(t, process.Start())

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if !test.expectErr {
_, err := process.WaitForEvent(ctx, TeleportReadyEvent)
require.NoError(t, err)
require.NoError(t, process.Close())
// Expect Teleport to shutdown without reporting any issue.
require.NoError(t, eg.Wait())
return
}

Expand All @@ -1838,6 +1848,9 @@ func TestInitDatabaseService(t *testing.T) {
exitPayload, ok := event.Payload.(ExitEventPayload)
require.True(t, ok, "expected ExitEventPayload but got %T", event.Payload)
require.Equal(t, "db.init", exitPayload.Service.Name())
// Database service init is a critical service, meaning failures on
// it should cause the process to exit with error.
require.Error(t, eg.Wait())
})
}
}
Expand Down
Loading