mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 19:44:01 +08:00

Turns out that `pool.Put(buf)` had to *allocate* because we needed to turn `[]byte` into `interface{}`. Apparently, we've never done this correctly we just never noticed because we never really used buffer pools extensively. However, since migrating yamux to a buffer-pool backed buffer, this started showing up in allocation profiles. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
testutil "gx/ipfs/QmNfQbgBfARAtrYsBguChX6VJ5nbjeoYy1KdC36aaYWqG8/go-testutil"
|
|
config "gx/ipfs/QmSoYrBMibm2T3LupaLuez7LPGnyrJwdRxvTfPUyCp691u/go-ipfs-config"
|
|
pstore "gx/ipfs/QmWtCpWB39Rzc2xTB75MKorsxNpo3TyecTEN24CJ3KVohE/go-libp2p-peerstore"
|
|
)
|
|
|
|
func TestSubsetWhenMaxIsGreaterThanLengthOfSlice(t *testing.T) {
|
|
var ps []pstore.PeerInfo
|
|
sizeofSlice := 100
|
|
for i := 0; i < sizeofSlice; i++ {
|
|
pid, err := testutil.RandPeerID()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ps = append(ps, pstore.PeerInfo{ID: pid})
|
|
}
|
|
out := randomSubsetOfPeers(ps, 2*sizeofSlice)
|
|
if len(out) != len(ps) {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestMultipleAddrsPerPeer(t *testing.T) {
|
|
var bsps []config.BootstrapPeer
|
|
for i := 0; i < 10; i++ {
|
|
pid, err := testutil.RandPeerID()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
addr := fmt.Sprintf("/ip4/127.0.0.1/tcp/5001/ipfs/%s", pid.Pretty())
|
|
bsp1, err := config.ParseBootstrapPeer(addr)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
addr = fmt.Sprintf("/ip4/127.0.0.1/udp/5002/utp/ipfs/%s", pid.Pretty())
|
|
bsp2, err := config.ParseBootstrapPeer(addr)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
bsps = append(bsps, bsp1, bsp2)
|
|
}
|
|
|
|
pinfos := toPeerInfos(bsps)
|
|
if len(pinfos) != len(bsps)/2 {
|
|
t.Fatal("expected fewer peers")
|
|
}
|
|
}
|