mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-24 08:01:06 +00:00
TestService: wait for OnConnect && OnDisconnect
This commit is contained in:
parent
8e65a78d07
commit
72dbfe2541
@ -72,15 +72,22 @@ func TestService(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
// run service
|
// wait for all dummy peers to connect and disconnect
|
||||||
go func() {
|
wg.Add(maxDummyPeers)
|
||||||
err := srvc.Start()
|
srvc.OnConnect = func(peer *protocol.CNPeer) {
|
||||||
is.NoErr(err) // srvc.Start error
|
wg.Done()
|
||||||
}()
|
}
|
||||||
|
|
||||||
|
wg.Add(maxDummyPeers)
|
||||||
|
srvc.OnDisconnect = func(peer *protocol.CNPeer) {
|
||||||
|
wg.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
// run service
|
||||||
|
go 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) // 2 wg.Done() calls per dummy peer
|
wg.Add(maxDummyPeers * 3) // 3 wg.Done() calls per dummy peer. 2 per peer for receiving packets, 1 for Handler() exit
|
||||||
for i := 0; i < maxDummyPeers; i++ {
|
for i := 0; i < maxDummyPeers; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
// make dummy client
|
// make dummy client
|
||||||
@ -93,8 +100,7 @@ func TestService(t *testing.T) {
|
|||||||
|
|
||||||
// send dummy packets
|
// send dummy packets
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
err := peer.Send(0x1234)
|
is.NoErr(peer.Send(0x1234)) // peer.Send error
|
||||||
is.NoErr(err) // peer.Send error
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user