Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
servicediscovery: fmt and handle timeout errors
Browse files Browse the repository at this point in the history
Signed-off-by: John Tuley <jtuley@pivotal.io>
  • Loading branch information
Mike Gehard authored and John Tuley committed Sep 3, 2014
1 parent 24462c4 commit 507ff1f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
7 changes: 6 additions & 1 deletion servicediscovery/servicediscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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))
}

Expand Down
47 changes: 33 additions & 14 deletions servicediscovery/servicediscovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})

0 comments on commit 507ff1f

Please sign in to comment.