MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestDHTService_FindNeighbor_FindNode

Function TestDHTService_FindNeighbor_FindNode

route/service_test.go:41–203  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39const DHTStorePath = "./DHTStore.keystore"
40
41func TestDHTService_FindNeighbor_FindNode(t *testing.T) {
42 utils.RemoveAll(DHTStorePath + "*")
43 defer utils.RemoveAll(DHTStorePath + "*")
44 log.SetLevel(log.DebugLevel)
45 addr := "127.0.0.1:0"
46 dht, _ := NewDHTService(DHTStorePath+"1", new(consistent.KMSStorage), false)
47 kms.ResetBucket()
48 rpc.RegisterName(DHTRPCName, dht)
49 ln, err := net.Listen("tcp", addr)
50 if err != nil {
51 fmt.Println(err)
52 return
53 }
54 go func() {
55 for {
56 c, err := ln.Accept()
57 if err != nil {
58 continue
59 }
60 go rpc.ServeConn(c)
61 }
62 }()
63
64 client, err := rpc.Dial("tcp", ln.Addr().String())
65 if err != nil {
66 log.Error(err)
67 }
68
69 req := &FindNeighborReq{
70 ID: "123",
71 Count: 2,
72 }
73 resp := new(FindNeighborResp)
74 err = client.Call("DHT.FindNeighbor", req, resp)
75 if err != nil {
76 log.Error(err)
77 }
78 log.Debugf("resp: %v", resp)
79
80 Convey("test FindNeighbor empty", t, func() {
81 So(resp.Nodes, ShouldBeEmpty)
82 So(err.Error(), ShouldContainSubstring, consistent.ErrEmptyCircle.Error())
83 })
84
85 reqFN1 := &FindNodeReq{
86 ID: "123",
87 }
88 respFN1 := new(FindNodeResp)
89 err = client.Call("DHT.FindNode", reqFN1, respFN1)
90 if err != nil {
91 log.Error(err)
92 }
93 log.Debugf("respFN1: %v", respFN1)
94 Convey("test FindNode", t, func() {
95 So(respFN1.Node, ShouldBeNil)
96 So(err.Error(), ShouldContainSubstring, consistent.ErrKeyNotFound.Error())
97 })
98

Callers

nothing calls this directly

Calls 15

InitNodeCryptoInfoMethod · 0.95
RemoveAllFunction · 0.92
SetLevelFunction · 0.92
ResetBucketFunction · 0.92
ErrorFunction · 0.92
DebugfFunction · 0.92
NewDHTServiceFunction · 0.85
NewNodeFunction · 0.85
PrintlnMethod · 0.80
AcceptMethod · 0.80
AddrMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected