Skip to content

Commit

Permalink
les/vflux/server: simplify inactiveAllowance == 0 case
Browse files Browse the repository at this point in the history
  • Loading branch information
zsfelfoldi committed Apr 16, 2021
1 parent 1d8abfe commit 12067b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
9 changes: 1 addition & 8 deletions les/vflux/server/clientpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,7 @@ func NewClientPool(balanceDb ethdb.KeyValueStore, minCap uint64, connectedBias t
if c, ok := ns.GetField(node, setup.clientField).(clientPeer); ok {
timeout = c.InactiveAllowance()
}
if timeout > 0 {
ns.AddTimeout(node, setup.inactiveFlag, timeout)
} else {
// Note: if capacity is immediately available then priorityPool will set the active
// flag simultaneously with removing the inactive flag and therefore this will not
// initiate disconnection
ns.SetStateSub(node, nodestate.Flags{}, setup.inactiveFlag, 0)
}
ns.AddTimeout(node, setup.inactiveFlag, timeout)
}
if oldState.Equals(setup.inactiveFlag) && newState.Equals(setup.inactiveFlag.Or(setup.priorityFlag)) {
ns.SetStateSub(node, setup.inactiveFlag, nodestate.Flags{}, 0) // priority gained; remove timeout
Expand Down
11 changes: 8 additions & 3 deletions les/vflux/server/clientpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,13 @@ func TestPaidClientKickedOut(t *testing.T) {
if cap := connect(pool, newPoolTestPeer(11, kickedCh)); cap == 0 {
t.Fatalf("Free client should be accepted")
}
clock.Run(0)
select {
case id := <-kickedCh:
if id != 0 {
t.Fatalf("Kicked client mismatch, want %v, got %v", 0, id)
}
case <-time.NewTimer(time.Second).C:
default:
t.Fatalf("timeout")
}
}
Expand Down Expand Up @@ -399,23 +400,27 @@ func TestFreeClientKickedOut(t *testing.T) {
if cap := connect(pool, newPoolTestPeer(10, kicked)); cap != 0 {
t.Fatalf("New free client should be rejected")
}
clock.Run(0)
select {
case <-kicked:
case <-time.NewTimer(time.Second).C:
default:
t.Fatalf("timeout")
}
disconnect(pool, newPoolTestPeer(10, kicked))
clock.Run(5 * time.Minute)
for i := 0; i < 10; i++ {
connect(pool, newPoolTestPeer(i+10, kicked))

}
clock.Run(0)

for i := 0; i < 10; i++ {
select {
case id := <-kicked:
if id >= 10 {
t.Fatalf("Old client should be kicked, now got: %d", id)
}
case <-time.NewTimer(time.Second).C:
default:
t.Fatalf("timeout")
}
}
Expand Down

0 comments on commit 12067b8

Please sign in to comment.