Stop using the sqlite backend in tests (#60153)

Swaps the lite backend for the memory backend in all tests that
can allow it. This could lead to reducing test times and is a
workaround for https://github.com/gravitational/teleport/issues/60127
- which is being addressed seperately.

The _only_ tests which have a hard requirement to use the sqlite backend
those which create a teleport process via service.NewTeleport. These
processes validate the the backend type is _not_ memory as that's not
a valid backend for a real Teleport process.
This commit is contained in:
rosstimothy
2025-10-10 16:13:25 -04:00
committed by GitHub
parent ae85f4452c
commit d012ba8148
8 changed files with 39 additions and 61 deletions
+2 -3
View File
@@ -66,8 +66,7 @@ import (
"github.com/gravitational/teleport/lib/auth/state"
"github.com/gravitational/teleport/lib/auth/storage"
"github.com/gravitational/teleport/lib/auth/testauthority"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/backend/lite"
"github.com/gravitational/teleport/lib/backend/memory"
"github.com/gravitational/teleport/lib/cryptosuites"
"github.com/gravitational/teleport/lib/modules"
"github.com/gravitational/teleport/lib/modules/modulestest"
@@ -1511,7 +1510,7 @@ func requireSystemResource(t *testing.T, argno int) func(mock.Arguments) {
func setupConfig(t *testing.T) auth.InitConfig {
tempDir := t.TempDir()
bk, err := lite.New(context.TODO(), backend.Params{"path": tempDir})
bk, err := memory.New(memory.Config{})
require.NoError(t, err)
processStorage, err := storage.NewProcessStorage(
+2 -2
View File
@@ -75,7 +75,7 @@ func TestAccessListMembers(t *testing.T) {
const numMembers = 32
p := newTestPack(t, ForAuth, memoryBackend(true))
p := newTestPack(t, ForAuth)
t.Cleanup(p.Close)
clock := clockwork.NewFakeClock()
@@ -381,7 +381,7 @@ func TestListAccessListsV2(t *testing.T) {
func TestCountAccessListMembersScoping(t *testing.T) {
t.Parallel()
p := newTestPack(t, ForAuth, memoryBackend(true))
p := newTestPack(t, ForAuth)
t.Cleanup(p.Close)
ctx := context.Background()
+6 -23
View File
@@ -78,7 +78,6 @@ import (
"github.com/gravitational/teleport/api/utils/keys"
"github.com/gravitational/teleport/entitlements"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/backend/lite"
"github.com/gravitational/teleport/lib/backend/memory"
"github.com/gravitational/teleport/lib/cryptosuites"
"github.com/gravitational/teleport/lib/defaults"
@@ -318,18 +317,11 @@ func newTestPackWithoutCache(t *testing.T) *testPack {
}
type packCfg struct {
memoryBackend bool
ignoreKinds []types.WatchKind
ignoreKinds []types.WatchKind
}
type packOption func(cfg *packCfg)
func memoryBackend(bool) packOption {
return func(cfg *packCfg) {
cfg.memoryBackend = true
}
}
// ignoreKinds specifies the list of kinds that should be removed from the watch request by eventsProxy
// to simulate cache resource type rejection due to version incompatibility.
func ignoreKinds(kinds []types.WatchKind) packOption {
@@ -349,19 +341,10 @@ func newPackWithoutCache(dir string, opts ...packOption) (*testPack, error) {
p := &testPack{
dataDir: dir,
}
var bk backend.Backend
var err error
if cfg.memoryBackend {
bk, err = memory.New(memory.Config{
Context: ctx,
Mirror: true,
})
} else {
bk, err = lite.NewWithConfig(ctx, lite.Config{
Path: p.dataDir,
PollStreamPeriod: 200 * time.Millisecond,
})
}
bk, err := memory.New(memory.Config{
Context: ctx,
Mirror: true,
})
if err != nil {
return nil, trace.Wrap(err)
}
@@ -1001,7 +984,7 @@ cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
BenchmarkListResourcesWithSort-8 1 2351035036 ns/op
*/
func BenchmarkListResourcesWithSort(b *testing.B) {
p, err := newPack(b.TempDir(), ForAuth, memoryBackend(true))
p, err := newPack(b.TempDir(), ForAuth)
require.NoError(b, err)
defer p.Close()
+1 -1
View File
@@ -124,7 +124,7 @@ func BenchmarkGetMaxNodes(b *testing.B) {
}
func benchGetNodes(b *testing.B, nodeCount int) {
p, err := newPack(b.TempDir(), ForAuth, memoryBackend(true))
p, err := newPack(b.TempDir(), ForAuth)
require.NoError(b, err)
defer p.Close()
+4 -5
View File
@@ -29,21 +29,20 @@ import (
identitycenterv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/identitycenter/v1"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/backend/lite"
"github.com/gravitational/teleport/lib/backend/memory"
"github.com/gravitational/teleport/lib/services"
)
func newTestBackend(t *testing.T, ctx context.Context, clock clockwork.Clock) backend.Backend {
t.Helper()
sqliteBackend, err := lite.NewWithConfig(ctx, lite.Config{
Path: t.TempDir(),
bk, err := memory.New(memory.Config{
Clock: clock,
})
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, sqliteBackend.Close())
require.NoError(t, bk.Close())
})
return sqliteBackend
return bk
}
func TestIdentityCenterResourceCRUD(t *testing.T) {
+19 -20
View File
@@ -42,7 +42,6 @@ import (
"github.com/gravitational/teleport/api/internalutils/stream"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/backend/lite"
"github.com/gravitational/teleport/lib/backend/memory"
"github.com/gravitational/teleport/lib/defaults"
)
@@ -53,11 +52,11 @@ func TestApplicationServersCRUD(t *testing.T) {
ctx := context.Background()
clock := clockwork.NewFakeClock()
backend, err := lite.NewWithConfig(ctx, lite.Config{
Path: t.TempDir(),
backend, err := memory.New(memory.Config{
Clock: clock,
})
require.NoError(t, err)
t.Cleanup(func() { _ = backend.Close() })
presence := NewPresenceService(backend)
@@ -159,11 +158,11 @@ func TestDatabaseServersCRUD(t *testing.T) {
ctx := context.Background()
clock := clockwork.NewFakeClock()
backend, err := lite.NewWithConfig(ctx, lite.Config{
Path: t.TempDir(),
backend, err := memory.New(memory.Config{
Clock: clock,
})
require.NoError(t, err)
t.Cleanup(func() { _ = backend.Close() })
presence := NewPresenceService(backend)
@@ -242,10 +241,11 @@ func TestDatabaseServersCRUD(t *testing.T) {
func TestNodeCRUD(t *testing.T) {
t.Parallel()
ctx := context.Background()
lite, err := lite.NewWithConfig(ctx, lite.Config{Path: t.TempDir()})
backend, err := memory.New(memory.Config{})
require.NoError(t, err)
t.Cleanup(func() { _ = backend.Close() })
presence := NewPresenceService(lite)
presence := NewPresenceService(backend)
node1, err := types.NewServerWithLabels("node1", types.KindNode, types.ServerSpecV2{}, nil)
require.NoError(t, err)
@@ -620,11 +620,11 @@ func TestListResources(t *testing.T) {
for testName, test := range tests {
t.Run(testName, func(t *testing.T) {
t.Parallel()
backend, err := lite.NewWithConfig(ctx, lite.Config{
Path: t.TempDir(),
backend, err := memory.New(memory.Config{
Clock: clock,
})
require.NoError(t, err)
t.Cleanup(func() { _ = backend.Close() })
presence := NewPresenceService(backend)
@@ -757,11 +757,11 @@ func TestListResources_Helpers(t *testing.T) {
ctx := context.Background()
clock := clockwork.NewFakeClock()
namespace := apidefaults.Namespace
bend, err := lite.NewWithConfig(ctx, lite.Config{
Path: t.TempDir(),
bend, err := memory.New(memory.Config{
Clock: clock,
})
require.NoError(t, err)
t.Cleanup(func() { _ = bend.Close() })
presence := NewPresenceService(bend)
tests := []struct {
@@ -939,11 +939,11 @@ func TestFakePaginate_TotalCount(t *testing.T) {
ctx := context.Background()
clock := clockwork.NewFakeClock()
namespace := apidefaults.Namespace
bend, err := lite.NewWithConfig(ctx, lite.Config{
Path: t.TempDir(),
bend, err := memory.New(memory.Config{
Clock: clock,
})
require.NoError(t, err)
t.Cleanup(func() { _ = bend.Close() })
presence := NewPresenceService(bend)
// Add some control servers.
@@ -1067,9 +1067,9 @@ func TestFakePaginate_TotalCount(t *testing.T) {
func TestPresenceService_CancelSemaphoreLease(t *testing.T) {
t.Parallel()
ctx := context.Background()
bk, err := lite.New(ctx, backend.Params{"path": t.TempDir()})
bk, err := memory.New(memory.Config{})
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, bk.Close()) })
t.Cleanup(func() { _ = bk.Close() })
presence := NewPresenceService(bk)
maxLeases := 5
@@ -1130,11 +1130,11 @@ func TestListResources_DuplicateResourceFilterByLabel(t *testing.T) {
t.Parallel()
ctx := context.Background()
backend, err := lite.NewWithConfig(ctx, lite.Config{
Path: t.TempDir(),
backend, err := memory.New(memory.Config{
Clock: clockwork.NewFakeClock(),
})
require.NoError(t, err)
t.Cleanup(func() { _ = backend.Close() })
presence := NewPresenceService(backend)
@@ -1255,10 +1255,9 @@ func TestServerInfoCRUD(t *testing.T) {
t.Parallel()
ctx := context.Background()
bk, err := lite.New(ctx, backend.Params{"path": t.TempDir()})
bk, err := memory.New(memory.Config{})
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, bk.Close()) })
t.Cleanup(func() { _ = bk.Close() })
presence := NewPresenceService(bk)
serverInfoA, err := types.NewServerInfo(types.Metadata{
@@ -27,20 +27,20 @@ import (
headerv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/header/v1"
provisioningv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/provisioning/v1"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/backend/lite"
"github.com/gravitational/teleport/lib/backend/memory"
"github.com/gravitational/teleport/lib/services"
)
func TestProvisioningUpdate(t *testing.T) {
ctx := context.Background()
backend, err := lite.NewWithConfig(ctx, lite.Config{
Path: t.TempDir(),
bk, err := memory.New(memory.Config{
Clock: clockwork.NewFakeClock(),
})
require.NoError(t, err)
t.Cleanup(func() { _ = bk.Close() })
uut, err := NewProvisioningStateService(backend)
uut, err := NewProvisioningStateService(bk)
require.NoError(t, err)
t.Run("downstream is honored", func(t *testing.T) {
+1 -3
View File
@@ -34,8 +34,6 @@ import (
"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth/testauthority"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/backend/lite"
"github.com/gravitational/teleport/lib/backend/memory"
"github.com/gravitational/teleport/lib/itertools/stream"
"github.com/gravitational/teleport/lib/tlsca"
@@ -488,7 +486,7 @@ func TestTrustedClusterCRUD(t *testing.T) {
t.Parallel()
ctx := context.Background()
bk, err := lite.New(ctx, backend.Params{"path": t.TempDir()})
bk, err := memory.New(memory.Config{})
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, bk.Close()) })