Skip to content

Commit

Permalink
chore: add test for Engine.CountConnections
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed May 18, 2023
1 parent 222a395 commit b493107
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ func (s *testServer) OnBoot(eng Engine) (action Action) {

func (s *testServer) OnOpen(c Conn) (out []byte, action Action) {
c.SetContext(c)
atomic.AddInt32(&s.connected, 1)
nclients := atomic.AddInt32(&s.connected, 1)
if int(nclients) == s.nclients {
require.EqualValuesf(s.tester, s.nclients, s.eng.CountConnections(), "expected connected clients: %d, but got: %d",
nclients, s.nclients)
}
out = []byte("sweetness\r\n")
require.NotNil(s.tester, c.LocalAddr(), "nil local addr")
require.NotNil(s.tester, c.RemoteAddr(), "nil remote addr")
Expand Down

0 comments on commit b493107

Please sign in to comment.