forked from TrueCloudLab/distribution
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)
This commit is contained in:
parent
6cd63c8bc0
commit
205e606a4c
1 changed files with 10 additions and 6 deletions
|
@ -89,25 +89,28 @@ func TestRestoreOld(t *testing.T) {
|
||||||
ref2.String(): true,
|
ref2.String(): true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(len(remainingRepos))
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
deleteFunc := func(r reference.Reference) error {
|
deleteFunc := func(r reference.Reference) error {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
if r.String() == ref1.String() && len(remainingRepos) == 2 {
|
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()]
|
_, ok := remainingRepos[r.String()]
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("Trying to remove nonexistent repo: %s", r)
|
t.Fatalf("Trying to remove nonexistent repo: %s", r)
|
||||||
}
|
}
|
||||||
mu.Lock()
|
|
||||||
delete(remainingRepos, r.String())
|
delete(remainingRepos, r.String())
|
||||||
mu.Unlock()
|
wg.Done()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
timeUnit := time.Millisecond
|
timeUnit := time.Millisecond
|
||||||
serialized, err := json.Marshal(&map[string]schedulerEntry{
|
serialized, err := json.Marshal(&map[string]schedulerEntry{
|
||||||
ref1.String(): {
|
ref1.String(): {
|
||||||
Expiry: time.Now().Add(1 * timeUnit),
|
Expiry: time.Now().Add(10 * timeUnit),
|
||||||
Key: ref1.String(),
|
Key: ref1.String(),
|
||||||
EntryType: 0,
|
EntryType: 0,
|
||||||
},
|
},
|
||||||
|
@ -129,13 +132,14 @@ func TestRestoreOld(t *testing.T) {
|
||||||
t.Fatal("Unable to write serialized data to fs")
|
t.Fatal("Unable to write serialized data to fs")
|
||||||
}
|
}
|
||||||
s := New(context.Background(), fs, "/ttl")
|
s := New(context.Background(), fs, "/ttl")
|
||||||
s.onBlobExpire = deleteFunc
|
s.OnBlobExpire(deleteFunc)
|
||||||
err = s.Start()
|
err = s.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error starting ttlExpirationScheduler: %s", err)
|
t.Fatalf("Error starting ttlExpirationScheduler: %s", err)
|
||||||
}
|
}
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
<-time.After(50 * timeUnit)
|
wg.Wait()
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
if len(remainingRepos) != 0 {
|
if len(remainingRepos) != 0 {
|
||||||
|
|
Loading…
Reference in a new issue