mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 10:44:02 +03:00
Rewrite to WaitGroup.Go
This commit is contained in:
@@ -52,17 +52,9 @@ func (suite *CircuitBreakerTestSuite) TestMultipleRunsOk() {
|
||||
Return(suite.connMock, nil)
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(5)
|
||||
|
||||
go func() {
|
||||
wg.Wait()
|
||||
suite.ctxCancel()
|
||||
}()
|
||||
|
||||
for range 5 {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
wg.Go(func() {
|
||||
conn, err := suite.d.DialContext(suite.ctx, "tcp", "127.0.0.1")
|
||||
|
||||
suite.mutex.Lock()
|
||||
@@ -70,9 +62,14 @@ func (suite *CircuitBreakerTestSuite) TestMultipleRunsOk() {
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal("127.0.0.1:3128", conn.RemoteAddr().String())
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
go func() {
|
||||
wg.Wait()
|
||||
suite.ctxCancel()
|
||||
}()
|
||||
|
||||
suite.Eventually(func() bool {
|
||||
_, ok := <-suite.ctx.Done()
|
||||
|
||||
|
||||
+4
-12
@@ -81,32 +81,24 @@ func (n *network) dnsResolve(protocol, address string) ([]string, error) {
|
||||
|
||||
switch protocol {
|
||||
case "tcp", "tcp4":
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
wg.Go(func() {
|
||||
resolved := n.dns.LookupA(address)
|
||||
|
||||
mutex.Lock()
|
||||
ips = append(ips, resolved...)
|
||||
mutex.Unlock()
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
switch protocol {
|
||||
case "tcp", "tcp6":
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
wg.Go(func() {
|
||||
resolved := n.dns.LookupAAAA(address)
|
||||
|
||||
mutex.Lock()
|
||||
ips = append(ips, resolved...)
|
||||
mutex.Unlock()
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
Reference in New Issue
Block a user