mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-07-02 14:11:35 +00:00
make dial queue parameters configurable.
This commit is contained in:
committed by
Matt Joiner
parent
1b1fb7e04f
commit
ebcfcd46a6
@ -12,7 +12,6 @@ import (
|
||||
)
|
||||
|
||||
func TestDialQueueGrowsOnSlowDials(t *testing.T) {
|
||||
|
||||
in := queue.NewChanQueue(context.Background(), queue.NewXORDistancePQ("test"))
|
||||
hang := make(chan struct{})
|
||||
|
||||
@ -29,7 +28,19 @@ func TestDialQueueGrowsOnSlowDials(t *testing.T) {
|
||||
}
|
||||
|
||||
// remove the mute period to grow faster.
|
||||
dq := newDialQueue(context.Background(), "test", in, dialFn, 10*time.Minute, 0)
|
||||
config := dqDefaultConfig()
|
||||
config.maxIdle = 10 * time.Minute
|
||||
config.mutePeriod = 0
|
||||
dq, err := newDialQueue(&dqParams{
|
||||
ctx: context.Background(),
|
||||
target: "test",
|
||||
in: in,
|
||||
dialFn: dialFn,
|
||||
config: config,
|
||||
})
|
||||
if err != nil {
|
||||
t.Error("unexpected error when constructing the dial queue", err)
|
||||
}
|
||||
|
||||
for i := 0; i < 4; i++ {
|
||||
_ = dq.Consume()
|
||||
@ -37,7 +48,7 @@ func TestDialQueueGrowsOnSlowDials(t *testing.T) {
|
||||
}
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
if atomic.LoadInt32(&cnt) > int32(DialQueueMinParallelism) {
|
||||
if atomic.LoadInt32(&cnt) > int32(DefaultDialQueueMinParallelism) {
|
||||
return
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
@ -61,7 +72,19 @@ func TestDialQueueShrinksWithNoConsumers(t *testing.T) {
|
||||
return nil
|
||||
}
|
||||
|
||||
dq := newDialQueue(context.Background(), "test", in, dialFn, 10*time.Minute, 0)
|
||||
config := dqDefaultConfig()
|
||||
config.maxIdle = 10 * time.Minute
|
||||
config.mutePeriod = 0
|
||||
dq, err := newDialQueue(&dqParams{
|
||||
ctx: context.Background(),
|
||||
target: "test",
|
||||
in: in,
|
||||
dialFn: dialFn,
|
||||
config: config,
|
||||
})
|
||||
if err != nil {
|
||||
t.Error("unexpected error when constructing the dial queue", err)
|
||||
}
|
||||
|
||||
// acquire 3 consumers, everytime we acquire a consumer, we will grow the pool because no dial job is completed
|
||||
// and immediately returnable.
|
||||
@ -121,7 +144,19 @@ func TestDialQueueShrinksWithWhenIdle(t *testing.T) {
|
||||
in.EnqChan <- peer.ID(i)
|
||||
}
|
||||
|
||||
dq := newDialQueue(context.Background(), "test", in, dialFn, time.Second, 0)
|
||||
config := dqDefaultConfig()
|
||||
config.maxIdle = 1 * time.Second
|
||||
config.mutePeriod = 0
|
||||
dq, err := newDialQueue(&dqParams{
|
||||
ctx: context.Background(),
|
||||
target: "test",
|
||||
in: in,
|
||||
dialFn: dialFn,
|
||||
config: config,
|
||||
})
|
||||
if err != nil {
|
||||
t.Error("unexpected error when constructing the dial queue", err)
|
||||
}
|
||||
|
||||
// keep up to speed with backlog by releasing the dial function every time we acquire a channel.
|
||||
for i := 0; i < 13; i++ {
|
||||
@ -162,7 +197,18 @@ func TestDialQueueMutePeriodHonored(t *testing.T) {
|
||||
in.EnqChan <- peer.ID(i)
|
||||
}
|
||||
|
||||
dq := newDialQueue(context.Background(), "test", in, dialFn, DialQueueMaxIdle, 2*time.Second)
|
||||
config := dqDefaultConfig()
|
||||
config.mutePeriod = 2 * time.Second
|
||||
dq, err := newDialQueue(&dqParams{
|
||||
ctx: context.Background(),
|
||||
target: "test",
|
||||
in: in,
|
||||
dialFn: dialFn,
|
||||
config: config,
|
||||
})
|
||||
if err != nil {
|
||||
t.Error("unexpected error when constructing the dial queue", err)
|
||||
}
|
||||
|
||||
// pick up three consumers.
|
||||
for i := 0; i < 3; i++ {
|
||||
|
Reference in New Issue
Block a user