From 3e8230bf0a20afebbcc52a085b20d34c2982aa6a Mon Sep 17 00:00:00 2001 From: Matt Reiferson Date: Tue, 31 Jul 2018 15:25:42 -0700 Subject: [PATCH 1/2] nsqd: set default value of lookupPeers --- nsqd/nsqd.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nsqd/nsqd.go b/nsqd/nsqd.go index 3c5437299..e6e586818 100644 --- a/nsqd/nsqd.go +++ b/nsqd/nsqd.go @@ -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{}) From a6aec9b513a3fce32bed2997d00d9dba0f8e7009 Mon Sep 17 00:00:00 2001 From: Matt Reiferson Date: Tue, 31 Jul 2018 15:25:51 -0700 Subject: [PATCH 2/2] nsqd: deflake TestReconfigure --- nsqd/nsqd_test.go | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/nsqd/nsqd_test.go b/nsqd/nsqd_test.go index 150a531b8..676ff446f 100644 --- a/nsqd/nsqd_test.go +++ b/nsqd/nsqd_test.go @@ -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) }