MCPcopy
hub / github.com/aceld/zinx / TestCloseConnectionBeforeSendMsg

Function TestCloseConnectionBeforeSendMsg

znet/server_test.go:191–214  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

189}
190
191func TestCloseConnectionBeforeSendMsg(t *testing.T) {
192 s := NewServer()
193 s.AddRouter(1, &CloseConnectionBeforeSendMsgRouter{})
194
195 s.Start()
196 time.Sleep(time.Second * 1)
197
198 wg := sync.WaitGroup{}
199 wg.Add(1)
200 go func() {
201 conn, _ := net.Dial("tcp", "127.0.0.1:8999")
202 dp := zpack.Factory().NewPack(ziface.ZinxDataPack)
203 msg := "Zinx client request message for CloseConnectionBeforeSendMsgRouter"
204 pack, _ := dp.Pack(zpack.NewMsgPackage(1, []byte(msg)))
205 _, _ = conn.Write(pack)
206 fmt.Println("send: ", msg)
207 buffer := make([]byte, 1024)
208 readLen, _ := conn.Read(buffer)
209 fmt.Println("received all data: ", string(buffer[dp.GetHeadLen():readLen]))
210 wg.Done()
211 }()
212 wg.Wait()
213 s.Stop()
214}

Callers

nothing calls this directly

Calls 11

AddRouterMethod · 0.95
StartMethod · 0.95
StopMethod · 0.95
FactoryFunction · 0.92
NewMsgPackageFunction · 0.92
NewServerFunction · 0.85
NewPackMethod · 0.80
WriteMethod · 0.80
AddMethod · 0.65
PackMethod · 0.65
GetHeadLenMethod · 0.65

Tested by

no test coverage detected