From 3252b0bcb971f5fa1bf204e6e099642b2f3c9fbc Mon Sep 17 00:00:00 2001 From: xenolf Date: Fri, 11 Mar 2016 04:51:02 +0100 Subject: [PATCH] Fix WaitFor calls --- acme/dns_challenge.go | 3 ++- acme/utils.go | 6 +++--- acme/utils_test.go | 2 +- providers/dns/route53/route53.go | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/acme/dns_challenge.go b/acme/dns_challenge.go index b7be186f..e5be0105 100644 --- a/acme/dns_challenge.go +++ b/acme/dns_challenge.go @@ -8,6 +8,7 @@ import ( "log" "net" "strings" + "time" "github.com/miekg/dns" "golang.org/x/net/publicsuffix" @@ -68,7 +69,7 @@ func (s *dnsChallenge) Solve(chlng challenge, domain string) error { logf("[INFO][%s] Checking DNS record propagation...", domain) - err = WaitFor(30, 2, func() (bool, error) { + err = WaitFor(60*time.Second, 2*time.Second, func() (bool, error) { return preCheckDNS(fqdn, value) }) if err != nil { diff --git a/acme/utils.go b/acme/utils.go index 937a8f2d..2fa0db30 100644 --- a/acme/utils.go +++ b/acme/utils.go @@ -5,10 +5,10 @@ import ( "time" ) -// WaitFor polls the given function 'f', once every 'interval' seconds, up to 'timeout' seconds. +// WaitFor polls the given function 'f', once every 'interval', up to 'timeout'. func WaitFor(timeout, interval time.Duration, f func() (bool, error)) error { var lastErr string - timeup := time.After(timeout * time.Second) + timeup := time.After(timeout) for { select { case <-timeup: @@ -24,6 +24,6 @@ func WaitFor(timeout, interval time.Duration, f func() (bool, error)) error { lastErr = err.Error() } - time.Sleep(interval * time.Second) + time.Sleep(interval) } } diff --git a/acme/utils_test.go b/acme/utils_test.go index cb837cd5..158af411 100644 --- a/acme/utils_test.go +++ b/acme/utils_test.go @@ -8,7 +8,7 @@ import ( func TestWaitForTimeout(t *testing.T) { c := make(chan error) go func() { - err := WaitFor(3, 1, func() (bool, error) { + err := WaitFor(3*time.Second, 1*time.Second, func() (bool, error) { return false, nil }) c <- err diff --git a/providers/dns/route53/route53.go b/providers/dns/route53/route53.go index bfca45ac..eb1ffdf3 100644 --- a/providers/dns/route53/route53.go +++ b/providers/dns/route53/route53.go @@ -71,7 +71,7 @@ func (r *DNSProvider) changeRecord(action, fqdn, value string, ttl int) error { return err } - return acme.WaitFor(90, 5, func() (bool, error) { + return acme.WaitFor(90*time.Second, 5*time.Second, func() (bool, error) { status, err := r.client.GetChange(resp.ChangeInfo.ID) if err != nil { return false, err