lichao
2021-05-18 cf05ea3d9f43e4e84d621e1f9d54cbef552b6e2b
api/bhsgo/bhome_node_test.go
@@ -1,17 +1,33 @@
package bhsgo
import (
   bh "bhshmq/proto/source/bhome_msg"
   "fmt"
   "testing"
   "time"
   "unsafe"
   bh "basic.com/valib/bhshmq.git/proto/source/bhome_msg"
)
func ServerCallback(src unsafe.Pointer, proc_id *string, req *bh.MsgRequestTopic) {
   fmt.Println("user server cb called, request topic: " + string(req.Topic) + ", data:" + string(req.Data))
   reply := bh.MsgRequestTopicReply{}
   reply.Data = []byte("reply 1234")
   SendReply(src, &reply)
}
func SubDataCallback(proc_id *string, pub *bh.MsgPublish) {
   fmt.Println("user sub data cb called")
}
func ClientCallback(proc_id *string, msg_id *[]byte, reply *bh.MsgRequestTopicReply) {
   fmt.Println("user client cb reply: " + string(reply.Data))
}
func TestRegister(t *testing.T) {
   proc_id := "test_proc"
   proc := bh.ProcInfo{}
   proc.ProcId = []byte(proc_id)
   reply := bh.MsgCommonReply{}
   defer Cleanup()
   StartWorker(ClientCallback, ServerCallback, SubDataCallback)
@@ -20,6 +36,21 @@
      fmt.Println("register ok")
   } else {
      fmt.Println("register failed")
      return
   }
   r = Unregister(&proc, &reply, 1000)
   if r {
      fmt.Println("Unregister ok")
   } else {
      fmt.Println("Unregister failed")
   }
   r = Register(&proc, &reply, 1000)
   if r {
      fmt.Println("register ok")
   } else {
      fmt.Println("register failed")
      t.Log("register error")
      return
   }
@@ -49,8 +80,9 @@
   pid := ""
   rr := bh.MsgRequestTopicReply{}
   dest := bh.BHAddress{}
   for i := 0; i < 10000; i++ {
      if Request(&req, &pid, &rr, 3000) {
      if Request(&dest, &req, &pid, &rr, 3000) {
         fmt.Println("server:" + pid + ", reply:" + string(rr.Data))
      } else {
         e, s := GetLastError()