client_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package v1
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/service/main/broadcast/model"
  7. "go-common/library/log"
  8. "go-common/library/naming/discovery"
  9. "go-common/library/net/netutil/breaker"
  10. "go-common/library/net/rpc/warden"
  11. "go-common/library/net/rpc/warden/resolver"
  12. xtime "go-common/library/time"
  13. )
  14. func testInit() ZergClient {
  15. log.Init(nil)
  16. conf := &warden.ClientConfig{
  17. Dial: xtime.Duration(time.Second * 10),
  18. Timeout: xtime.Duration(time.Second * 10),
  19. Breaker: &breaker.Config{
  20. Window: xtime.Duration(3 * time.Second),
  21. Sleep: xtime.Duration(3 * time.Second),
  22. Bucket: 10,
  23. Ratio: 0.3,
  24. Request: 20,
  25. },
  26. }
  27. wc := warden.NewClient(conf)
  28. resolver.Register(discovery.New(nil))
  29. conn, err := wc.Dial(context.TODO(), "discovery://default/push.interface.broadcast")
  30. if err != nil {
  31. panic(err)
  32. }
  33. return NewZergClient(conn)
  34. }
  35. func TestPushMsg(t *testing.T) {
  36. client := testInit()
  37. time.Sleep(10 * time.Second)
  38. client.PushMsg(context.Background(), &PushMsgReq{
  39. Keys: []string{"test"},
  40. ProtoOp: model.OpSendMsg,
  41. Proto: &model.Proto{
  42. Ver: 0,
  43. SeqId: 0,
  44. Operation: model.OpSendMsgReply,
  45. Body: []byte("{\"test1111111\"}"),
  46. },
  47. })
  48. }
  49. /*
  50. func TestBroadcastMsg(t *testing.T) {
  51. client := testInit()
  52. client.Broadcast(context.Background(), 102, &model.Proto{
  53. Ver: 0,
  54. SeqId: 0,
  55. Operation: define.OP_SEND_SMS_REPLY,
  56. Body: []byte("{\"test broadcast 104\"}"),
  57. })
  58. }
  59. func TestBroadcastRoom(t *testing.T) {
  60. client := testInit()
  61. client.BroadcastRoom(context.Background(), "test_room", &model.Proto{
  62. Ver: 0,
  63. SeqId: 0,
  64. Operation: define.OP_SEND_SMS_REPLY,
  65. Body: []byte("{\"test broadcast\"}"),
  66. })
  67. }
  68. func TestRooms(t *testing.T) {
  69. client := testInit()
  70. rooms, err := client.Rooms(context.Background())
  71. if err != nil {
  72. t.Fatal(err)
  73. }
  74. t.Logf("TestRooms.rooms:%v", rooms)
  75. }
  76. */