Skip to content

Commit

Permalink
util/quotapool: fix name propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
ajwerner committed Jul 2, 2019
1 parent ef016d9 commit 3f0ccce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion pkg/util/quotapool/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type optionFunc func(cfg *config)
func (f optionFunc) apply(cfg *config) { f(cfg) }

type config struct {
name string
onSlowAcquisition SlowAcquisitionFunc
slowAcquisitionThreshold time.Duration
}
6 changes: 4 additions & 2 deletions pkg/util/quotapool/intpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ func TestSlowAcquisition(t *testing.T) {
firstKey := ctxKey(1)
firstCtx := context.WithValue(ctx, firstKey, "foo")
slowCalled, acquiredCalled := make(chan struct{}), make(chan struct{})
f := func(ctx context.Context, _ string, _ quotapool.Request, _ time.Time) func() {
const poolName = "test"
f := func(ctx context.Context, name string, _ quotapool.Request, _ time.Time) func() {
assert.Equal(t, poolName, name)
if ctx.Value(firstKey) != nil {
return func() {}
}
Expand All @@ -322,7 +324,7 @@ func TestSlowAcquisition(t *testing.T) {
close(acquiredCalled)
}
}
qp := quotapool.NewIntPool("test", 1, quotapool.OnSlowAcquisition(time.Microsecond, f))
qp := quotapool.NewIntPool(poolName, 1, quotapool.OnSlowAcquisition(time.Microsecond, f))
alloc, err := qp.Acquire(firstCtx, 1)
if err != nil {
t.Fatal(err)
Expand Down
5 changes: 5 additions & 0 deletions pkg/util/quotapool/quotapool.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (ec *ErrClosed) Error() string {
type QuotaPool struct {
config

// name is used for logging purposes and is passed to functions used to report
// acquistions or slow acqusitions.
name string

// chanSyncPool is used to pool allocations of the channels used to notify
// goroutines waiting in Acquire.
chanSyncPool sync.Pool
Expand Down Expand Up @@ -134,6 +138,7 @@ type QuotaPool struct {
// acquired without ever making more than the quota capacity available.
func New(name string, initialResource Resource, options ...Option) *QuotaPool {
qp := &QuotaPool{
name: name,
quota: make(chan Resource, 1),
done: make(chan struct{}),
chanSyncPool: sync.Pool{
Expand Down

0 comments on commit 3f0ccce

Please sign in to comment.