diff --git a/registry/proxy/scheduler/scheduler_test.go b/registry/proxy/scheduler/scheduler_test.go index b74ae4f9..4d69d5b5 100644 --- a/registry/proxy/scheduler/scheduler_test.go +++ b/registry/proxy/scheduler/scheduler_test.go @@ -89,25 +89,28 @@ func TestRestoreOld(t *testing.T) { ref2.String(): true, } + var wg sync.WaitGroup + wg.Add(len(remainingRepos)) var mu sync.Mutex deleteFunc := func(r reference.Reference) error { + mu.Lock() + defer mu.Unlock() if r.String() == ref1.String() && len(remainingRepos) == 2 { - t.Errorf("ref1 should be removed first") + t.Errorf("ref1 should not be removed first") } _, ok := remainingRepos[r.String()] if !ok { t.Fatalf("Trying to remove nonexistent repo: %s", r) } - mu.Lock() delete(remainingRepos, r.String()) - mu.Unlock() + wg.Done() return nil } timeUnit := time.Millisecond serialized, err := json.Marshal(&map[string]schedulerEntry{ ref1.String(): { - Expiry: time.Now().Add(1 * timeUnit), + Expiry: time.Now().Add(10 * timeUnit), Key: ref1.String(), EntryType: 0, }, @@ -129,13 +132,14 @@ func TestRestoreOld(t *testing.T) { t.Fatal("Unable to write serialized data to fs") } s := New(context.Background(), fs, "/ttl") - s.onBlobExpire = deleteFunc + s.OnBlobExpire(deleteFunc) err = s.Start() if err != nil { t.Fatalf("Error starting ttlExpirationScheduler: %s", err) } + defer s.Stop() - <-time.After(50 * timeUnit) + wg.Wait() mu.Lock() defer mu.Unlock() if len(remainingRepos) != 0 {