From 5976bba0b5dd67d2169641a5c3dab935155fb885 Mon Sep 17 00:00:00 2001 From: Alexandre Garand Date: Tue, 9 Jul 2019 10:20:59 +0200 Subject: [PATCH] fix the tests the ips are now fetched correctly a sleep was put in the destroy check to ensure that the api have time to destroy before it is checked --- mailgun/resource_mailgun_domain.go | 18 ++++++++++++++---- mailgun/resource_mailgun_domain_test.go | 7 ++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/mailgun/resource_mailgun_domain.go b/mailgun/resource_mailgun_domain.go index 86531c6..e2bfe73 100644 --- a/mailgun/resource_mailgun_domain.go +++ b/mailgun/resource_mailgun_domain.go @@ -366,7 +366,7 @@ func DeleteDomain(d *schema.ResourceData, meta interface{}) error { func ReadDomain(d *schema.ResourceData, meta interface{}) error { mg := meta.(*mailgun.MailgunImpl) - ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*120) defer cancel() domainName := d.Id() mg = mailgun.NewMailgun(domainName, mg.APIKey()) @@ -425,9 +425,7 @@ func ReadDomain(d *schema.ResourceData, meta interface{}) error { d.Set("unsubscribe_tracking_settings_html_footer", domainTracking.Unsubscribe.HTMLFooter) d.Set("unsubscribe_tracking_settings_text_footer", domainTracking.Unsubscribe.TextFooter) - time.Sleep(25 * time.Second) - - ipAddress, err := mg.ListDomainIPS(ctx) + ipAddress, err := getIps(ctx, mg) if err != nil { return fmt.Errorf("Error Getting mailgun domain ips1 for %s: Error: %s", d.Id(), err) @@ -493,3 +491,15 @@ func ImportStatePassthroughDomain(d *schema.ResourceData, meta interface{}) ([]* } return []*schema.ResourceData{d}, nil } + +func getIps(ctx context.Context,mg *mailgun.MailgunImpl) ([]mailgun.IPAddress, error){ + start := time.Now() + t := time.Now() + ipAddress, err := mg.ListDomainIPS(ctx) + for (err != nil && t.Sub(start)< 120 * time.Second) { + ipAddress, err = mg.ListDomainIPS(ctx) + time.Sleep(5 * time.Second) + t = time.Now() + } + return ipAddress, err +} diff --git a/mailgun/resource_mailgun_domain_test.go b/mailgun/resource_mailgun_domain_test.go index 952e013..a129b1f 100644 --- a/mailgun/resource_mailgun_domain_test.go +++ b/mailgun/resource_mailgun_domain_test.go @@ -21,7 +21,7 @@ type fullDomain struct { } func getFullDomain(mg *mailgun.MailgunImpl, domainName string) (*fullDomain, error) { - ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*120) defer cancel() mg = mailgun.NewMailgun(domainName, mg.APIKey()) @@ -42,7 +42,8 @@ func getFullDomain(mg *mailgun.MailgunImpl, domainName string) (*fullDomain, err return nil, fmt.Errorf("Error Getting mailgun domain tracking Details for %s: Error: %s", domainName, err) } - ipAddress, err := mg.ListDomainIPS(ctx) + ipAddress, err := getIps(ctx, mg) + if err != nil { return nil, fmt.Errorf("Error Getting mailgun domain ips2 for %s: Error: %s", domainName, err) } @@ -209,7 +210,7 @@ func testAccDomainCheckDestroy(domain *fullDomain) resource.TestCheckFunc { mg := testAccProvider.Meta().(*mailgun.MailgunImpl) ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) defer cancel() - + time.Sleep(5 * time.Second) _, err := mg.GetDomain(ctx, domain.domainResponse.Domain.Name) if err == nil { return fmt.Errorf("domain still exists") -- 2.41.0