From 507ff1f4ef7749879a14b12fd2c42d654c99b2f2 Mon Sep 17 00:00:00 2001 From: Mike Gehard Date: Wed, 3 Sep 2014 16:21:45 -0600 Subject: [PATCH] servicediscovery: fmt and handle timeout errors Signed-off-by: John Tuley --- servicediscovery/servicediscovery.go | 7 +++- servicediscovery/servicediscovery_test.go | 47 ++++++++++++++++------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/servicediscovery/servicediscovery.go b/servicediscovery/servicediscovery.go index 7c3502e..d172b35 100644 --- a/servicediscovery/servicediscovery.go +++ b/servicediscovery/servicediscovery.go @@ -48,6 +48,11 @@ func (list *serverAddressList) Run(updateInterval time.Duration) { continue } + if err == storeadapter.ErrorTimeout { + list.logger.Debug("ServerAddressList.Run: Timed out talking to store; will try again soon.") + continue + } + if err != nil { panic(err) //FIXME: understand error modes and recovery cases better } @@ -56,7 +61,7 @@ func (list *serverAddressList) Run(updateInterval time.Duration) { addresses := []string{} - for _, leaf := range leaves { + for _, leaf := range leaves { addresses = append(addresses, string(leaf.Value)) } diff --git a/servicediscovery/servicediscovery_test.go b/servicediscovery/servicediscovery_test.go index 7c00d3f..dd567cb 100644 --- a/servicediscovery/servicediscovery_test.go +++ b/servicediscovery/servicediscovery_test.go @@ -121,25 +121,44 @@ var _ = Describe("ServiceDiscovery", func() { go list.Run(1 * time.Millisecond) - Eventually(list.GetAddresses).Should(HaveLen(1)) + Eventually(list.GetAddresses).Should(HaveLen(1)) - storeAdapter.Lock() - storeAdapter.ListErrInjector = fakestoreadapter.NewFakeStoreAdapterErrorInjector("", storeadapter.ErrorKeyNotFound) - storeAdapter.Unlock() + storeAdapter.Lock() + storeAdapter.ListErrInjector = fakestoreadapter.NewFakeStoreAdapterErrorInjector("", storeadapter.ErrorKeyNotFound) + storeAdapter.Unlock() - Consistently(list.GetAddresses).Should(HaveLen(1)) + Consistently(list.GetAddresses).Should(HaveLen(1)) }) - It("excludes nodes with no value", func() { - node := storeadapter.StoreNode{ - Key: "/healthstatus/loggregator/z1/loggregator_z1", - Value: []byte{}, - } + It("continues to run if the store times out", func() { + node := storeadapter.StoreNode{ + Key: "/healthstatus/loggregator/z1/loggregator_z1", + Value: []byte("10.0.0.1"), + } - storeAdapter.Create(node) + storeAdapter.Create(node) - go list.Run(1 * time.Millisecond) + go list.Run(1 * time.Millisecond) + + Eventually(list.GetAddresses).Should(HaveLen(1)) + + storeAdapter.Lock() + storeAdapter.ListErrInjector = fakestoreadapter.NewFakeStoreAdapterErrorInjector("", storeadapter.ErrorTimeout) + storeAdapter.Unlock() - Consistently(list.GetAddresses).Should(BeEmpty()) - }) + Consistently(list.GetAddresses).Should(HaveLen(1)) + }) + + It("excludes nodes with no value", func() { + node := storeadapter.StoreNode{ + Key: "/healthstatus/loggregator/z1/loggregator_z1", + Value: []byte{}, + } + + storeAdapter.Create(node) + + go list.Run(1 * time.Millisecond) + + Consistently(list.GetAddresses).Should(BeEmpty()) + }) })