-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix zone record cache lookups when prefetch is enabled (#206)
This Pull Request implements the following updates: - Corrects the method by which the prefetch configuration flag is loaded from the environment. - Introduces concurrent read/write locking for the cache to prevent panics during simultaneous map writes. - Adjusts the logic for searching zone records in the cache, utilizing the normalized content value rather than the initially configured value.
- Loading branch information
Showing
5 changed files
with
60 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,7 +146,10 @@ func TestAccZoneRecordResourceWithPrefetch(t *testing.T) { | |
resourceName := "dnsimple_zone_record.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { test_utils.TestAccPreCheck(t) }, | ||
PreCheck: func() { | ||
test_utils.TestAccPreCheck(t) | ||
t.Setenv("DNSIMPLE_PREFETCH", "1") | ||
}, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
CheckDestroy: testAccCheckZoneRecordResourceDestroy, | ||
Steps: []resource.TestStep{ | ||
|
@@ -165,6 +168,32 @@ func TestAccZoneRecordResourceWithPrefetch(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccZoneRecordResource_Prefetch_Normalized(t *testing.T) { | ||
domainName := os.Getenv("DNSIMPLE_DOMAIN") | ||
resourceName := "dnsimple_zone_record.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
test_utils.TestAccPreCheck(t) | ||
t.Setenv("DNSIMPLE_PREFETCH", "1") | ||
}, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
CheckDestroy: testAccCheckZoneRecordResourceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccZoneRecordResourceNormalizedContentConfig(domainName), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceName, "zone_name", domainName), | ||
resource.TestCheckResourceAttr(resourceName, "qualified_name", "terraform."+domainName), | ||
resource.TestCheckResourceAttr(resourceName, "ttl", "3600"), | ||
resource.TestCheckResourceAttrSet(resourceName, "id"), | ||
), | ||
}, | ||
// Delete testing automatically occurs in TestCase | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccZoneRecordResource_Prefetch_ForEach(t *testing.T) { | ||
// Issue: https://github.com/dnsimple/terraform-provider-dnsimple/issues/80 | ||
// This test is to ensure that the prefetch behaviour is deterministic | ||
|
@@ -177,7 +206,7 @@ func TestAccZoneRecordResource_Prefetch_ForEach(t *testing.T) { | |
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
test_utils.TestAccPreCheck(t) | ||
os.Setenv("PREFETCH", "1") | ||
t.Setenv("DNSIMPLE_PREFETCH", "1") | ||
}, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
|
@@ -312,6 +341,17 @@ resource "dnsimple_zone_record" "test" { | |
}`, domainName) | ||
} | ||
|
||
func testAccZoneRecordResourceNormalizedContentConfig(domainName string) string { | ||
return fmt.Sprintf(` | ||
resource "dnsimple_zone_record" "test" { | ||
zone_name = %[1]q | ||
name = "terraform" | ||
value = "v=DMARC1; p=reject; pct=100; mailto:[email protected]; aspf=r;" | ||
type = "TXT" | ||
}`, domainName) | ||
} | ||
|
||
func testAccZoneRecordResourceStandardConfig(domainName string) string { | ||
return fmt.Sprintf(` | ||
resource "dnsimple_zone_record" "test" { | ||
|