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 <derek@mcgstyle.net> (github: dmcgowan)
pull/1925/head
Derek McGowan 2016-08-29 14:27:32 -07:00
parent 6cd63c8bc0
commit 205e606a4c
1 changed files with 10 additions and 6 deletions

View File

@ -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 {