From 205e606a4c143599315e53c403de5d2f8f9ed1b3 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Mon, 29 Aug 2016 14:27:32 -0700 Subject: [PATCH] Update proxy scheduler test to account for race Running with the race detector may cause some parts of the code to run slower causing a race in the scheduler ordering. Signed-off-by: Derek McGowan (github: dmcgowan) --- registry/proxy/scheduler/scheduler_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 {