Skip to content

Commit

Permalink
Merge pull request #1066 from mreiferson/deflake-test-reconfigure
Browse files Browse the repository at this point in the history
nsqd: deflake TestReconfigure
  • Loading branch information
ploxiln authored Jul 31, 2018
2 parents 28c013b + a6aec9b commit de7d001
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions nsqd/nsqd.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func New(opts *Options) *NSQD {
httpcli := http_api.NewClient(nil, opts.HTTPClientConnectTimeout, opts.HTTPClientRequestTimeout)
n.ci = clusterinfo.New(n.logf, httpcli)

n.lookupPeers.Store([]*lookupPeer{})

n.swapOpts(opts)
n.errValue.Store(errStore{})

Expand Down
33 changes: 22 additions & 11 deletions nsqd/nsqd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,32 +368,43 @@ func TestReconfigure(t *testing.T) {
defer os.RemoveAll(opts.DataPath)
defer nsqd.Exit()

time.Sleep(250 * time.Millisecond)

newOpts := *opts
newOpts := NewOptions()
newOpts.Logger = opts.Logger
newOpts.NSQLookupdTCPAddresses = []string{lookupd1.RealTCPAddr().String()}
nsqd.swapOpts(&newOpts)
nsqd.swapOpts(newOpts)
nsqd.triggerOptsNotification()
test.Equal(t, 1, len(nsqd.getOpts().NSQLookupdTCPAddresses))

time.Sleep(350 * time.Millisecond)

numLookupPeers := len(nsqd.lookupPeers.Load().([]*lookupPeer))
var numLookupPeers int
for i := 0; i < 100; i++ {
numLookupPeers = len(nsqd.lookupPeers.Load().([]*lookupPeer))
if numLookupPeers == 1 {
break
}
time.Sleep(10 * time.Millisecond)
}
test.Equal(t, 1, numLookupPeers)

newOpts = *opts
newOpts = NewOptions()
newOpts.Logger = opts.Logger
newOpts.NSQLookupdTCPAddresses = []string{lookupd2.RealTCPAddr().String(), lookupd3.RealTCPAddr().String()}
nsqd.swapOpts(&newOpts)
nsqd.swapOpts(newOpts)
nsqd.triggerOptsNotification()
test.Equal(t, 2, len(nsqd.getOpts().NSQLookupdTCPAddresses))

time.Sleep(350 * time.Millisecond)
for i := 0; i < 100; i++ {
numLookupPeers = len(nsqd.lookupPeers.Load().([]*lookupPeer))
if numLookupPeers == 2 {
break
}
time.Sleep(10 * time.Millisecond)
}
test.Equal(t, 2, numLookupPeers)

var lookupPeers []string
for _, lp := range nsqd.lookupPeers.Load().([]*lookupPeer) {
lookupPeers = append(lookupPeers, lp.addr)
}
test.Equal(t, 2, len(lookupPeers))
test.Equal(t, newOpts.NSQLookupdTCPAddresses, lookupPeers)
}

Expand Down

0 comments on commit de7d001

Please sign in to comment.