From 2b67c54790b209f4cda4f3c7c2a3e6dcf899031a Mon Sep 17 00:00:00 2001 From: Vyzaldy Sanchez Date: Wed, 16 Oct 2024 18:48:14 -0400 Subject: [PATCH] Fixes syncer test race (#14772) --- core/services/registrysyncer/syncer_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/services/registrysyncer/syncer_test.go b/core/services/registrysyncer/syncer_test.go index 8aaa49eab0a..03f9bffcf92 100644 --- a/core/services/registrysyncer/syncer_test.go +++ b/core/services/registrysyncer/syncer_test.go @@ -144,6 +144,7 @@ func (l *launcher) Launch(ctx context.Context, localRegistry *registrysyncer.Loc type orm struct { ormMock *syncerMocks.ORM + mu sync.RWMutex latestLocalRegistryCh chan struct{} addLocalRegistryCh chan struct{} } @@ -159,17 +160,23 @@ func newORM(t *testing.T) *orm { } func (o *orm) Cleanup() { + o.mu.Lock() + defer o.mu.Unlock() close(o.latestLocalRegistryCh) close(o.addLocalRegistryCh) } func (o *orm) AddLocalRegistry(ctx context.Context, localRegistry registrysyncer.LocalRegistry) error { + o.mu.Lock() + defer o.mu.Unlock() o.addLocalRegistryCh <- struct{}{} err := o.ormMock.AddLocalRegistry(ctx, localRegistry) return err } func (o *orm) LatestLocalRegistry(ctx context.Context) (*registrysyncer.LocalRegistry, error) { + o.mu.Lock() + defer o.mu.Unlock() o.latestLocalRegistryCh <- struct{}{} return o.ormMock.LatestLocalRegistry(ctx) }