2018-09-05 01:07:44 +08:00
|
|
|
package pstoremem
|
2018-08-30 20:44:50 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-05-31 21:51:16 +08:00
|
|
|
pstore "github.com/libp2p/go-libp2p-core/peerstore"
|
2018-09-08 01:46:23 +08:00
|
|
|
pt "github.com/libp2p/go-libp2p-peerstore/test"
|
2020-03-24 05:16:16 +08:00
|
|
|
|
|
|
|
"go.uber.org/goleak"
|
2018-08-30 20:44:50 +08:00
|
|
|
)
|
|
|
|
|
2020-03-24 05:16:16 +08:00
|
|
|
func TestFuzzInMemoryPeerstore(t *testing.T) {
|
|
|
|
// Just create and close a bunch of peerstores. If this leaks, we'll
|
|
|
|
// catch it in the leak check below.
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
ps := NewPeerstore()
|
|
|
|
ps.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 20:44:50 +08:00
|
|
|
func TestInMemoryPeerstore(t *testing.T) {
|
2018-09-08 01:46:23 +08:00
|
|
|
pt.TestPeerstore(t, func() (pstore.Peerstore, func()) {
|
2020-03-24 05:16:16 +08:00
|
|
|
ps := NewPeerstore()
|
|
|
|
return ps, func() { ps.Close() }
|
2018-08-30 20:44:50 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-05 22:08:33 +08:00
|
|
|
func TestInMemoryAddrBook(t *testing.T) {
|
2018-09-08 01:46:23 +08:00
|
|
|
pt.TestAddrBook(t, func() (pstore.AddrBook, func()) {
|
2020-03-24 05:16:16 +08:00
|
|
|
ps := NewPeerstore()
|
|
|
|
return ps, func() { ps.Close() }
|
2018-08-30 20:44:50 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-08-31 19:59:46 +08:00
|
|
|
func TestInMemoryKeyBook(t *testing.T) {
|
2018-09-08 01:46:23 +08:00
|
|
|
pt.TestKeyBook(t, func() (pstore.KeyBook, func()) {
|
2020-03-24 05:16:16 +08:00
|
|
|
ps := NewPeerstore()
|
|
|
|
return ps, func() { ps.Close() }
|
2018-08-31 19:59:46 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-08-30 20:44:50 +08:00
|
|
|
func BenchmarkInMemoryPeerstore(b *testing.B) {
|
2018-09-08 01:46:23 +08:00
|
|
|
pt.BenchmarkPeerstore(b, func() (pstore.Peerstore, func()) {
|
2020-03-24 05:16:16 +08:00
|
|
|
ps := NewPeerstore()
|
|
|
|
return ps, func() { ps.Close() }
|
2018-09-04 18:34:55 +08:00
|
|
|
}, "InMem")
|
2018-08-30 21:13:27 +08:00
|
|
|
}
|
2018-10-29 18:17:10 +08:00
|
|
|
|
|
|
|
func BenchmarkInMemoryKeyBook(b *testing.B) {
|
|
|
|
pt.BenchmarkKeyBook(b, func() (pstore.KeyBook, func()) {
|
2020-03-24 05:16:16 +08:00
|
|
|
ps := NewPeerstore()
|
|
|
|
return ps, func() { ps.Close() }
|
2018-10-29 18:17:10 +08:00
|
|
|
})
|
|
|
|
}
|
2020-03-24 05:16:16 +08:00
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
goleak.VerifyTestMain(
|
|
|
|
m,
|
|
|
|
goleak.IgnoreTopFunction("github.com/ipfs/go-log/writer.(*MirrorWriter).logRoutine"),
|
|
|
|
)
|
|
|
|
}
|