7 "github.com/google/btree"
8 "github.com/stretchr/testify/assert"
11 func TestPrioritizedPeers(t *testing.T) {
12 pp := prioritizedPeers{
14 getPrio: func(p PeerInfo) peerPriority {
15 return bep40PriorityIgnoreError(p.addr(), IpPort{IP: net.ParseIP("0.0.0.0")})
18 _, ok := pp.DeleteMin()
19 assert.Panics(t, func() { pp.PopMax() })
22 {Addr: ipPortAddr{IP: net.ParseIP("1.2.3.4")}},
23 {Addr: ipPortAddr{IP: net.ParseIP("1::2")}},
24 {Addr: ipPortAddr{IP: net.ParseIP("")}},
25 {Addr: ipPortAddr{IP: net.ParseIP("")}, Trusted: true},
27 for i, p := range ps {
28 t.Logf("peer %d priority: %08x trusted: %t\n", i, pp.getPrio(p), p.Trusted)
29 assert.False(t, pp.Add(p))
30 assert.True(t, pp.Add(p))
31 assert.Equal(t, i+1, pp.Len())
33 pop := func(expected *PeerInfo) {
35 assert.Panics(t, func() { pp.PopMax() })
37 assert.Equal(t, *expected, pp.PopMax())
40 min := func(expected *PeerInfo) {
41 i, ok := pp.DeleteMin()
46 assert.Equal(t, *expected, i.p)