Skip to content

Commit 1784e13

Browse files
committed
fix unit test
1 parent ab5072e commit 1784e13

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

cluster_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,7 @@ func (s *S) TestDoNotFallbackToMonotonic(c *C) {
20922092

20932093
func (s *S) TestConnectServerFailed(c *C) {
20942094
dials := int32(0)
2095-
maxDials := 100
2095+
maxDials := 50
20962096
info := &mgo.DialInfo{
20972097
Addrs: []string{"localhost:40001"},
20982098
DialServer: func(addr *mgo.ServerAddr) (net.Conn, error) {
@@ -2112,16 +2112,18 @@ func (s *S) TestConnectServerFailed(c *C) {
21122112

21132113
errs := make(chan error, 1)
21142114
var done int32
2115-
var wg sync.WaitGroup
2115+
var finished sync.WaitGroup
2116+
var starting sync.WaitGroup
21162117
defer func() {
21172118
atomic.StoreInt32(&done, 1)
2118-
wg.Wait()
2119+
finished.Wait()
21192120
}()
21202121
for i := 0; i < maxDials; i++ {
2121-
wg.Add(1)
2122+
finished.Add(1)
2123+
starting.Add(1)
21222124
go func(s0 *mgo.Session) {
2123-
defer wg.Done()
2124-
for {
2125+
defer finished.Done()
2126+
for i := 0; ; i++ {
21252127
if atomic.LoadInt32(&done) == 1 {
21262128
break
21272129
}
@@ -2139,10 +2141,14 @@ func (s *S) TestConnectServerFailed(c *C) {
21392141
default:
21402142
}
21412143
}
2144+
if i == 0 {
2145+
starting.Done()
2146+
}
21422147
}
21432148
}(session)
21442149
time.Sleep(10 * time.Millisecond)
21452150
}
2151+
starting.Wait()
21462152

21472153
// no errors expect.
21482154
var opErr error

0 commit comments

Comments
 (0)