(t *testing.T)
| 18 | } |
| 19 | |
| 20 | func 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 | |
| 61 | func TestClient_WaitTimeout(t *testing.T) { |
| 62 | q := New("channel") |
nothing calls this directly
no test coverage detected