From b4931079ba57206971681fa292b088b80bac86c1 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Thu, 18 May 2023 21:56:27 +0800 Subject: [PATCH] chore: add test for Engine.CountConnections --- gnet_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gnet_test.go b/gnet_test.go index 708f03933..e5bcc0ff3 100644 --- a/gnet_test.go +++ b/gnet_test.go @@ -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")