MCPcopy Create free account
hub / github.com/33cn/chain33 / TestTimeout

Function TestTimeout

queue/queue_test.go:20–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18}
19
20func TestTimeout(t *testing.T) {
21 //send timeout and recv timeout
22 q := New("channel")
23
24 //mempool
25 go func() {
26 client := q.Client()
27 client.Sub("mempool")
28 for msg := range client.Recv() {
29 if msg.Ty == types.EventTx {
30 time.Sleep(time.Second)
31 msg.Reply(client.NewMessage("mempool", types.EventReply, types.Reply{IsOk: true, Msg: []byte("word")}))
32 }
33 }
34 }()
35 client := q.Client()
36 //rpc 模块 会向其他模块发送消息,自己本身不需要订阅消息
37 msg := client.NewMessage("blockchain", types.EventTx, "hello")
38 for i := 0; i < defaultChanBuffer; i++ {
39 err := client.SendTimeout(msg, true, 0)
40 if err != nil {
41 t.Error(err)
42 return
43 }
44 }
45
46 //再发送一个交易返回chain full
47 err := client.SendTimeout(msg, true, 0)
48 if err != ErrQueueChannelFull {
49 t.Error(err)
50 return
51 }
52
53 //发送一个交易返回返回timeout
54 err = client.SendTimeout(msg, true, time.Millisecond)
55 if err != ErrQueueTimeout {
56 t.Error(err)
57 return
58 }
59}
60
61func TestClient_WaitTimeout(t *testing.T) {
62 q := New("channel")

Callers

nothing calls this directly

Calls 8

ReplyMethod · 0.95
NewFunction · 0.70
ClientMethod · 0.65
SubMethod · 0.65
RecvMethod · 0.65
NewMessageMethod · 0.65
SendTimeoutMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected