From: Peter Amstutz Date: Mon, 14 Jan 2019 19:13:20 +0000 (-0500) Subject: 14324: Fix API throttling header fallbacks. Add gocheck_test X-Git-Tag: 1.4.0~174^2~1 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/6756ee790a6c685b96bc1ec80b67e7d6c94e9846?hp=f398e9d75d32fbfa6804041353997bf74195e489 14324: Fix API throttling header fallbacks. Add gocheck_test Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- diff --git a/lib/cloud/azure.go b/lib/cloud/azure.go index d94285d6ad..a194b33180 100644 --- a/lib/cloud/azure.go +++ b/lib/cloud/azure.go @@ -166,15 +166,14 @@ func WrapAzureError(err error) error { if parseErr != nil { // Could not parse as a timestamp, must be number of seconds dur, parseErr := strconv.ParseInt(ra, 10, 64) - if parseErr != nil { + if parseErr == nil { earliestRetry = time.Now().Add(time.Duration(dur) * time.Second) + } else { + // Couldn't make sense of retry-after, + // so set retry to 20 seconds + earliestRetry = time.Now().Add(20 * time.Second) } } - if parseErr != nil { - // Couldn't make sense of retry-after, - // so set retry to 20 seconds - earliestRetry = time.Now().Add(20 * time.Second) - } return &AzureRateLimitError{*rq, earliestRetry} } if rq.ServiceError == nil { @@ -251,10 +250,14 @@ func (az *AzureInstanceSet) setup(azcfg AzureInstanceSetConfig, dispatcherID str az.ctx, az.stopFunc = context.WithCancel(context.Background()) go func() { + az.stopWg.Add(1) + defer az.stopWg.Done() + tk := time.NewTicker(5 * time.Minute) for { select { case <-az.ctx.Done(): + tk.Stop() return case <-tk.C: az.ManageBlobs() @@ -504,9 +507,6 @@ func (az *AzureInstanceSet) ManageNics() (map[string]network.Interface, error) { // leased to a VM) and haven't been modified for // DeleteDanglingResourcesAfter seconds. func (az *AzureInstanceSet) ManageBlobs() { - az.stopWg.Add(1) - defer az.stopWg.Done() - result, err := az.storageAcctClient.ListKeys(az.ctx, az.azconfig.ResourceGroup, az.azconfig.StorageAccount) if err != nil { az.logger.WithError(err).Warn("Couldn't get account keys") diff --git a/lib/cloud/gocheck_test.go b/lib/cloud/gocheck_test.go new file mode 100644 index 0000000000..d8392686ab --- /dev/null +++ b/lib/cloud/gocheck_test.go @@ -0,0 +1,16 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +package cloud + +import ( + "testing" + + check "gopkg.in/check.v1" +) + +// Gocheck boilerplate +func Test(t *testing.T) { + check.TestingT(t) +}