(t *testing.T)
| 39 | const DHTStorePath = "./DHTStore.keystore" |
| 40 | |
| 41 | func 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 |
nothing calls this directly
no test coverage detected