8000 Fixed data race in TestSchedule test by horoshev · Pull Request #4647 · distribution/distribution · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixed data race in TestSchedule test #4647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions registry/proxy/scheduler/scheduler_test.go 8000
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package scheduler

import (
"encoding/json"
"fmt"
"sync"
"testing"
"time"

"github.com/distribution/reference"

"github.com/distribution/distribution/v3/internal/dcontext"
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
"github.com/distribution/reference"
)

func testRefs(t *testing.T) (reference.Reference, reference.Reference, reference.Reference) {
Expand All @@ -30,13 +32,34 @@ func testRefs(t *testing.T) (reference.Reference, reference.Reference, reference
return ref1, ref2, ref3
}

func testRefsN(t *testing.T, n int) []reference.Canonical {
refs := make([]reference.Canonical, 0, n)
for i := range n {
name := "testrepo@sha256:" + fmt.Sprintf("%064d", i)

ref, err := reference.Parse(name)
if err != nil {
t.Fatalf("could not parse reference: %v", err)
}

canonical, ok := ref.(reference.Canonical)
if !ok {
t.Fatalf("not canonical reference: %v", ref)
}

refs = append(refs, canonical)
}

return refs
}

func TestSchedule(t *testing.T) {
ref1, ref2, ref3 := testRefs(t)
refs := testRefsN(t, 20)
timeUnit := time.Millisecond
remainingRepos := map[string]bool{
ref1.String(): true,
ref2.String(): true,
ref3.String(): true,

remainingRepos := map[string]bool{}
for _, ref := range refs {
remainingRepos[ref.String()] = true
}

var mu sync.Mutex
Expand All @@ -62,14 +85,9 @@ func TestSchedule(t *testing.T) {
t.Fatalf("Error starting ttlExpirationScheduler: %s", err)
}

s.add(ref1, 3*timeUnit, entryTypeBlob)
s.add(ref2, 1*timeUnit, entryTypeBlob)

func() {
s.Lock()
s.add(ref3, 1*timeUnit, entryTypeBlob)
s.Unlock()
}()
for i, ref := range refs {
_ = s.AddBlob(ref, time.Duration(i)*timeUnit)
}

// Ensure all repos are deleted
<-time.After(50 * timeUnit)
Expand Down
Loading
0