From 9997b1ff23b925f8200d24027aaa8629cbae24b1 Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Tue, 2 Jan 2024 15:33:03 -0800 Subject: [PATCH 1/2] fix flaky lib/auth cache-enabled tests --- lib/auth/helpers.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/auth/helpers.go b/lib/auth/helpers.go index 64e5179a6947e..4bd4976c1c0c4 100644 --- a/lib/auth/helpers.go +++ b/lib/auth/helpers.go @@ -307,6 +307,7 @@ func NewTestAuthServer(cfg TestAuthServerConfig) (*TestAuthServer, error) { Setup: cache.ForAuth, CacheName: []string{teleport.ComponentAuth}, Events: true, + Unstarted: true, }) if err != nil { return nil, trace.Wrap(err) @@ -432,6 +433,13 @@ func NewTestAuthServer(cfg TestAuthServerConfig) (*TestAuthServer, error) { return nil, trace.Wrap(err) } + // Auth initialization is done (including creation/updating of all singleton + // configuration resources) so now we can start the cache. + if c, ok := srv.AuthServer.Cache.(*cache.Cache); ok { + if err := c.Start(); err != nil { + return nil, trace.Wrap(err) + } + } return srv, nil } From 95ae313e3a4c3ef0d04aaab0bcc4b2b053ce1721 Mon Sep 17 00:00:00 2001 From: Gavin Frazar Date: Wed, 3 Jan 2024 10:40:37 -0800 Subject: [PATCH 2/2] use auth server close context for cache in tests --- lib/auth/helpers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/auth/helpers.go b/lib/auth/helpers.go index 4bd4976c1c0c4..8e603541da7db 100644 --- a/lib/auth/helpers.go +++ b/lib/auth/helpers.go @@ -302,7 +302,7 @@ func NewTestAuthServer(cfg TestAuthServerConfig) (*TestAuthServer, error) { if cfg.CacheEnabled { srv.AuthServer.Cache, err = accesspoint.NewAccessCache(accesspoint.AccessCacheConfig{ - Context: ctx, + Context: srv.AuthServer.CloseContext(), Services: srv.AuthServer.Services, Setup: cache.ForAuth, CacheName: []string{teleport.ComponentAuth}, @@ -437,7 +437,7 @@ func NewTestAuthServer(cfg TestAuthServerConfig) (*TestAuthServer, error) { // configuration resources) so now we can start the cache. if c, ok := srv.AuthServer.Cache.(*cache.Cache); ok { if err := c.Start(); err != nil { - return nil, trace.Wrap(err) + return nil, trace.NewAggregate(err, c.Close()) } } return srv, nil