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.
nnet/test/test_nnet_test.go

51 lines
1005 B
Go

package main
import (
"git.noahlan.cn/noahlan/nnet/connection"
"git.noahlan.cn/noahlan/nnet/packet"
"git.noahlan.cn/noahlan/nnet/protocol/nnet"
rt "git.noahlan.cn/noahlan/nnet/router"
"git.noahlan.cn/noahlan/ntools-go/core/nlog"
"sync"
"testing"
)
func TestServer(t *testing.T) {
runServer("0.0.0.0:6666")
}
func TestClient(t *testing.T) {
ngin, et := runClient("127.0.0.1:6666")
ngin.AddRoutes(rt.Route{
Matches: nnet.Match{
Route: "pong",
Code: 2,
},
Handler: func(conn *connection.Connection, pkg packet.IPacket) {
nlog.Info("server pong, client ping ->")
_ = et.Send(nnet.Header{
PacketType: nnet.Data,
MessageHeader: nnet.MessageHeader{
MsgType: nnet.Request,
ID: 1,
Route: "ping",
},
}, []byte("1"))
},
})
_ = et.Send(nnet.Header{
PacketType: nnet.Data,
MessageHeader: nnet.MessageHeader{
MsgType: nnet.Request,
ID: 1,
Route: "ping",
},
}, []byte("1"))
var wg sync.WaitGroup
wg.Add(1)
wg.Wait()
}