MCPcopy Create free account
hub / github.com/DNAProject/DNA / TestP2PActorServer

Function TestP2PActorServer

p2pserver/actor/server/actor_test.go:34–148  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32)
33
34func TestP2PActorServer(t *testing.T) {
35 log.InitLog(log.InfoLog, log.Stdout)
36 fmt.Println("Start test the p2pserver by actor...")
37
38 p2p := p2pserver.NewServer()
39 if p2p == nil {
40 t.Fatalf("TestP2PActorServer: p2pserver NewServer error")
41 }
42
43 p2pActor := NewP2PActor(p2p)
44 p2pPID, err := p2pActor.Start()
45 if err != nil {
46 t.Fatalf("p2pActor init error %s", err)
47 }
48
49 //test server api
50
51 future := p2pPID.RequestFuture(&GetConnectionCntReq{}, common.ACTOR_TIMEOUT*time.Second)
52 result, err := future.Result()
53 if err != nil {
54 t.Errorf("GetConnectionCntReq error %s", err)
55 }
56 _, ok := result.(*GetConnectionCntRsp)
57 if !ok {
58 t.Error("GetConnectionCntRsp error")
59 }
60
61 future = p2pPID.RequestFuture(&GetNeighborAddrsReq{}, common.ACTOR_TIMEOUT*time.Second)
62 result, err = future.Result()
63 if err != nil {
64 t.Errorf("GetNeighborAddrsReq error %s", err)
65 }
66 _, ok = result.(*GetNeighborAddrsRsp)
67 if !ok {
68 t.Error("GetNeighborAddrsRsp error")
69 }
70
71 future = p2pPID.RequestFuture(&GetConnectionStateReq{}, common.ACTOR_TIMEOUT*time.Second)
72 result, err = future.Result()
73 if err != nil {
74 t.Errorf("GetConnectionStateReq error %s", err)
75 }
76 _, ok = result.(*GetConnectionStateRsp)
77 if !ok {
78 t.Error("GetConnectionStateRsp error")
79 }
80
81 future = p2pPID.RequestFuture(&GetTimeReq{}, common.ACTOR_TIMEOUT*time.Second)
82 result, err = future.Result()
83 if err != nil {
84 t.Errorf("GetTimeReq error %s", err)
85 }
86 _, ok = result.(*GetTimeRsp)
87 if !ok {
88 t.Error("GetTimeRsp error")
89 }
90
91 future = p2pPID.RequestFuture(&GetPortReq{}, common.ACTOR_TIMEOUT*time.Second)

Callers

nothing calls this directly

Calls 7

StartMethod · 0.95
InitLogFunction · 0.92
NewServerFunction · 0.92
NewP2PActorFunction · 0.85
FatalfMethod · 0.80
ErrorfMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected