func TestTimer(t *testing.T) { signal := test.NewSignalTester(t) pipe := cellnet.NewEventPipe() evq := pipe.AddQueue() pipe.Start() const testTimes = 3 var count int = testTimes cellnet.NewTimer(evq, time.Second, func(t *cellnet.Timer) { log.Debugln("timer 1 sec tick") signal.Done(1) count-- if count == 0 { t.Stop() signal.Done(2) } }) for i := 0; i < testTimes; i++ { signal.WaitAndExpect(1, "timer not tick") } signal.WaitAndExpect(2, "timer not stop") }
func TestRPC(t *testing.T) { signal = test.NewSignalTester(t) server() client() }
func TestClose(t *testing.T) { signal = test.NewSignalTester(t) runServer() testConnActiveClose() testRecvDisconnected() }
func TestGate(t *testing.T) { signal = test.NewSignalTester(t) routerServer() backendServer() client() }
func TestIO(t *testing.T) { // 屏蔽socket层的调试日志 golog.SetLevelByString("socket", "error") signal = test.NewSignalTester(t) // 超时时间为测试时间延迟一会 signal.SetTimeout((benchmarkSeconds + 5) * time.Second) server() for i := 0; i < clientCount; i++ { go client() } signal.WaitAndExpect(1, "recv time out") }
func TestDelay(t *testing.T) { signal := test.NewSignalTester(t) pipe := cellnet.NewEventPipe() evq := pipe.AddQueue() pipe.Start() log.Debugln("delay 1 sec begin") evq.DelayPostData(time.Second, func() { log.Debugln("delay done") signal.Done(1) }) signal.WaitAndExpect(1, "delay not work") }
func TestMongoDB(t *testing.T) { signal = test.NewSignalTester(t) db() }