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

Function TestDHTService_Ping

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

Source from the content-addressed store, hash-verified

203}
204
205func TestDHTService_Ping(t *testing.T) {
206 utils.RemoveAll(DHTStorePath + "*")
207 defer utils.RemoveAll(DHTStorePath + "*")
208 log.SetLevel(log.DebugLevel)
209 addr := "127.0.0.1:0"
210
211 dht, _ := NewDHTService(DHTStorePath, new(consistent.KMSStorage), false)
212 rpc.RegisterName(DHTRPCName, dht)
213 ln, err := net.Listen("tcp", addr)
214 if err != nil {
215 fmt.Println(err)
216 return
217 }
218
219 go func() {
220 for {
221 c, err := ln.Accept()
222 if err != nil {
223 continue
224 }
225 go rpc.ServeCodec(utils.GetMsgPackServerCodec(c))
226 }
227 }()
228
229 client, err := net.Dial("tcp", ln.Addr().String())
230 if err != nil {
231 log.Error(err)
232 }
233
234 NewNodeIDDifficultyTimeout = 100 * time.Millisecond
235 node1 := NewNode()
236 node1.InitNodeCryptoInfo(100 * time.Millisecond)
237
238 reqA := &PingReq{
239 Node: *node1,
240 }
241 respA := new(PingResp)
242 rc := rpc.NewClientWithCodec(utils.GetMsgPackClientCodec(client))
243 err = rc.Call("DHT.Ping", reqA, respA)
244 if err != nil {
245 t.Error(err)
246 }
247 log.Debugf("respA: %v", respA)
248 rc.Close()
249
250 respA3 := new(PingResp)
251 conf.GConf.MinNodeIDDifficulty = 256
252 client, _ = net.Dial("tcp", ln.Addr().String())
253 rc = rpc.NewClientWithCodec(utils.GetMsgPackClientCodec(client))
254 err = rc.Call("DHT.Ping", reqA, respA3)
255 if err == nil || !strings.Contains(err.Error(), "difficulty too low") {
256 t.Error(err)
257 }
258 log.Debugf("respA3: %v", respA3)
259 rc.Close()
260
261 respA2 := new(PingResp)
262 reqA.Node.Nonce.A = ^uint64(0)

Callers

nothing calls this directly

Calls 15

InitNodeCryptoInfoMethod · 0.95
RemoveAllFunction · 0.92
SetLevelFunction · 0.92
GetMsgPackServerCodecFunction · 0.92
ErrorFunction · 0.92
GetMsgPackClientCodecFunction · 0.92
DebugfFunction · 0.92
NewDHTServiceFunction · 0.85
NewNodeFunction · 0.85
PrintlnMethod · 0.80
AcceptMethod · 0.80
AddrMethod · 0.80

Tested by

no test coverage detected