mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-07 09:17:49 +08:00
- Modified Godeps/Godeps.json by hand - [TEST] Updated welcome docs hash to sharness - [TEST] Updated contact doc - [TEST] disabled breaking test (t0080-repo refs local)
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package decision
|
|
|
|
import (
|
|
"math"
|
|
"math/rand"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/ipfs/go-ipfs/exchange/bitswap/wantlist"
|
|
"github.com/ipfs/go-ipfs/util"
|
|
"github.com/ipfs/go-ipfs/util/testutil"
|
|
)
|
|
|
|
func TestPushPop(t *testing.T) {
|
|
prq := newPRQ()
|
|
partner := testutil.RandPeerIDFatal(t)
|
|
alphabet := strings.Split("abcdefghijklmnopqrstuvwxyz", "")
|
|
vowels := strings.Split("aeiou", "")
|
|
consonants := func() []string {
|
|
var out []string
|
|
for _, letter := range alphabet {
|
|
skip := false
|
|
for _, vowel := range vowels {
|
|
if letter == vowel {
|
|
skip = true
|
|
}
|
|
}
|
|
if !skip {
|
|
out = append(out, letter)
|
|
}
|
|
}
|
|
return out
|
|
}()
|
|
sort.Strings(alphabet)
|
|
sort.Strings(vowels)
|
|
sort.Strings(consonants)
|
|
|
|
// add a bunch of blocks. cancel some. drain the queue. the queue should only have the kept entries
|
|
|
|
for _, index := range rand.Perm(len(alphabet)) { // add blocks for all letters
|
|
letter := alphabet[index]
|
|
t.Log(partner.String())
|
|
prq.Push(wantlist.Entry{Key: util.Key(letter), Priority: math.MaxInt32 - index}, partner)
|
|
}
|
|
for _, consonant := range consonants {
|
|
prq.Remove(util.Key(consonant), partner)
|
|
}
|
|
|
|
for _, expected := range vowels {
|
|
received := prq.Pop().Entry.Key
|
|
if received != util.Key(expected) {
|
|
t.Fatal("received", string(received), "expected", string(expected))
|
|
}
|
|
}
|
|
}
|