package notify import ( "fmt" "sync/atomic" "testing" "time" ) func Test_ServerTuAndClientCommon(t *testing.T) { server, err := NewNotifyS("tcp", "127.0.0.1:12345") if err != nil { panic(err) } server.SetNotify("notify", notify) for i := 1; i <= 1; i++ { go func() { client, err := NewNotifyC("tcp", "127.0.0.1:12345") if err != nil { time.Sleep(time.Second * 2) panic(err) } for { //nowd = time.Now().UnixNano() client.SendValueWait("notify", "client hello", time.Second*50) //time.Sleep(time.Millisecond) //fmt.Println("finished:", float64(time.Now().UnixNano()-nowd)/1000000) //client.Send("notify", []byte("client hello")) } }() } go func() { time.Sleep(time.Second * 10) server.ServerStop() }() <-server.Stoped() //time.Sleep(time.Second * 5) fmt.Println(count2) } var count2 int64 func notify(msg SMsg) string { //fmt.Println(string(msg.Msg.Value)) //fmt.Println("called:", float64(time.Now().UnixNano()-nowd)/1000000) go atomic.AddInt64(&count2, 1) return "ok" }