diff --git a/lib/services/access_request_cache.go b/lib/services/access_request_cache.go index c0615b1c78205..100458ef49061 100644 --- a/lib/services/access_request_cache.go +++ b/lib/services/access_request_cache.go @@ -344,6 +344,7 @@ func (c *AccessRequestCache) getResourcesAndUpdateCurrent(ctx context.Context) e c.rw.Lock() defer c.rw.Unlock() c.primaryCache = cache + close(c.initC) return nil } @@ -394,6 +395,12 @@ func (c *AccessRequestCache) initializationChan() <-chan struct{} { return c.initC } +// InitializationChan is part of the resourceCollector interface and gets the channel +// used to signal that the accessRequestCache has been initialized. +func (c *AccessRequestCache) InitializationChan() <-chan struct{} { + return c.initializationChan() +} + // Close terminates the background process that keeps the access request cache up to // date, and terminates any inflight load operations. func (c *AccessRequestCache) Close() error { diff --git a/lib/services/access_request_cache_test.go b/lib/services/access_request_cache_test.go index 4bf95399c61d2..d34aa948fe064 100644 --- a/lib/services/access_request_cache_test.go +++ b/lib/services/access_request_cache_test.go @@ -51,6 +51,12 @@ func newAccessRequestPack(t *testing.T) (accessRequestServices, *services.Access }) require.NoError(t, err) + select { + case <-cache.InitializationChan(): + case <-time.After(time.Second * 30): + require.FailNow(t, "timeout waiting for access request cache to initialize") + } + return svcs, cache }