MCPcopy Create free account
hub / github.com/DOSNetwork/core / TestRequest

Function TestRequest

p2p/client_test.go:87–163  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestRequest(t *testing.T) {
88 var listenerA net.Listener
89 var err error
90 if listenerA, err = net.Listen("tcp", ":9902"); err != nil {
91 return
92 }
93 go listen(t, listenerA, "server")
94
95 add := "localhost:9902"
96 var conn net.Conn
97 var client *client
98 if conn, err = net.Dial("tcp", add); err != nil {
99 t.Errorf("Can't Dial to %s ,Error %s", add, err.Error())
100 }
101 suite := suites.MustFind("bn256")
102 secret := suite.Scalar().Pick(suite.RandomStream())
103 public := suite.Point().Mul(secret, nil)
104
105 client, err = newClient(suite, secret, public, []byte("local"), conn, false)
106 if err != nil {
107 t.Errorf("newClient,Error %s", err.Error())
108 }
109 var count uint64
110 checkRoll := make(map[uint64]uint64)
111 var wg sync.WaitGroup
112 wg.Add(1)
113 for count = 0; count < 1; count++ {
114 go func(count uint64) {
115 defer wg.Done()
116
117 callReq := request{}
118 callReq.ctx, callReq.cancel = context.WithTimeout(context.Background(), 35*time.Second)
119 callReq.rType = 1
120 callReq.id = client.remoteID
121 callReq.reply = make(chan interface{})
122 callReq.errc = make(chan error)
123 defer close(callReq.reply)
124 defer close(callReq.errc)
125 callReq.msg = proto.Message(&Ping{Count: count})
126 client.send(callReq)
127
128 select {
129 case r, ok := <-callReq.reply:
130 if !ok {
131 return
132 }
133 msg, ok := r.(P2PMessage)
134 if ok {
135
136 }
137 p, ok := msg.Msg.Message.(*Pong)
138 if !ok {
139 t.Errorf("casting failed")
140 }
141 checkRoll[count] = p.Count
142 return
143 case e, ok := <-callReq.errc:
144 if ok {

Callers

nothing calls this directly

Calls 11

sendMethod · 0.95
listenFunction · 0.85
newClientFunction · 0.85
ListenMethod · 0.65
ErrorMethod · 0.65
PickMethod · 0.45
ScalarMethod · 0.45
RandomStreamMethod · 0.45
MulMethod · 0.45
PointMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected