This repository was archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathkad_lookup_test.go
More file actions
59 lines (49 loc) · 1.46 KB
/
kad_lookup_test.go
File metadata and controls
59 lines (49 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package holochain
import (
"fmt"
. "github.com/holochain/holochain-proto/hash"
peer "github.com/libp2p/go-libp2p-peer"
. "github.com/smartystreets/goconvey/convey"
"testing"
_ "time"
)
func TestGetClosestPeers(t *testing.T) {
nodesCount := 30
mt := setupMultiNodeTesting(nodesCount)
defer mt.cleanupMultiNodeTesting()
nodes := mt.nodes
randConnect(t, mt.ctx, nodes, nodesCount, 7, 4)
Convey("it should return a list of close peers", t, func() {
fooHash, _ := NewHash("QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHx")
//fooHash := HashFromPeerID(nodes[29].node.HashAddr)
peers, err := nodes[1].node.GetClosestPeers(mt.ctx, fooHash)
So(err, ShouldBeNil)
var out []peer.ID
for p := range peers {
out = append(out, p)
}
So(len(out), ShouldEqual, KValue)
})
starConnect(t, mt.ctx, nodes, nodesCount)
Convey("nodes should agree on who's the closest to a hash", t, func() {
hash, _ := NewHash("QmS4bKx7zZt6qoX2om5M5ik3X2k4Fco2nFx82CDJ3iVKj2")
var closest peer.ID
for i, h := range nodes {
peers, err := h.node.GetClosestPeers(mt.ctx, hash)
if err != nil {
fmt.Printf("%d--%v: %v", i, h.nodeID.Pretty(), err)
} else {
var out []peer.ID
for p := range peers {
out = append(out, p)
}
//fmt.Printf("%v thinks %v,%v is closest\n", h.nodeID.Pretty()[2:4], out[0].Pretty()[2:4], out[1].Pretty()[2:4])
if i != 0 {
So(closest.Pretty(), ShouldEqual, out[0].Pretty())
} else {
closest = out[0]
}
}
}
})
}