You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
3 years ago
|
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"
|
||
|
}
|