TestService: minor refactor; clearer waitgroup Add

This commit is contained in:
CPunch 2023-12-01 14:08:17 -06:00
parent 72dbfe2541
commit 66fe3c9738

View File

@ -66,6 +66,7 @@ func TestService(t *testing.T) {
}() }()
// our dummy packet handler // our dummy packet handler
wg.Add(maxDummyPeers)
srvc.AddPacketHandler(0x1234, func(peer *protocol.CNPeer, pkt protocol.Packet) error { srvc.AddPacketHandler(0x1234, func(peer *protocol.CNPeer, pkt protocol.Packet) error {
log.Printf("Received packet %#v", pkt) log.Printf("Received packet %#v", pkt)
wg.Done() wg.Done()
@ -84,10 +85,10 @@ func TestService(t *testing.T) {
} }
// run service // run service
go is.NoErr(srvc.Start()) // srvc.Start error go func() { is.NoErr(srvc.Start()) }() // srvc.Start error
is.True(selectWithTimeout(srvc.Started(), timeout)) // wait for service to start with timeout is.True(selectWithTimeout(srvc.Started(), timeout)) // wait for service to start with timeout
wg.Add(maxDummyPeers * 3) // 3 wg.Done() calls per dummy peer. 2 per peer for receiving packets, 1 for Handler() exit wg.Add(maxDummyPeers * 2) // 2 wg.Done() per peer for receiving packets
for i := 0; i < maxDummyPeers; i++ { for i := 0; i < maxDummyPeers; i++ {
go func() { go func() {
// make dummy client // make dummy client