Skip to content

Commit b493107

Browse files
committed
chore: add test for Engine.CountConnections
1 parent 222a395 commit b493107

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

gnet_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ func (s *testServer) OnBoot(eng Engine) (action Action) {
243243

244244
func (s *testServer) OnOpen(c Conn) (out []byte, action Action) {
245245
c.SetContext(c)
246-
atomic.AddInt32(&s.connected, 1)
246+
nclients := atomic.AddInt32(&s.connected, 1)
247+
if int(nclients) == s.nclients {
248+
require.EqualValuesf(s.tester, s.nclients, s.eng.CountConnections(), "expected connected clients: %d, but got: %d",
249+
nclients, s.nclients)
250+
}
247251
out = []byte("sweetness\r\n")
248252
require.NotNil(s.tester, c.LocalAddr(), "nil local addr")
249253
require.NotNil(s.tester, c.RemoteAddr(), "nil remote addr")

0 commit comments

Comments
 (0)