Skip to content

Commit

Permalink
add test for concurrent map access panic
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 committed May 10, 2021
1 parent 9650439 commit ff82981
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion nomad/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"os"
"reflect"
"strings"
"testing"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -132,12 +133,15 @@ func TestAccNomadProvider_Headers(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactoryInternal(&provider),
CheckDestroy: nil,
CheckDestroy: testAccCheckNomadProviderConfigWithHeadersCrashCheckDestroy(provider),
Steps: []resource.TestStep{
{
Config: testAccNomadProviderConfigWithHeaders,
Check: testAccCheckNomadProviderConfigWithHeaders(provider),
},
{
Config: testAccNomadProviderConfigWithHeadersCrash,
},
},
})
}
Expand All @@ -160,6 +164,30 @@ func testAccCheckNomadProviderConfigWithHeaders(provider *schema.Provider) resou
}
}

func testAccCheckNomadProviderConfigWithHeadersCrashCheckDestroy(provider *schema.Provider) resource.TestCheckFunc {
return func(_ *terraform.State) error {
providerConfig := provider.Meta().(ProviderConfig)
client := providerConfig.client
namespaces, _, err := client.Namespaces().List(nil)
if err != nil {
return err
}

count := 0
namespacePrefix := "headers-crash-test"
for _, ns := range namespaces {
if strings.HasPrefix(ns.Name, namespacePrefix) {
count++
}
}

if count != 0 {
return fmt.Errorf("%d namespaces still registered", count)
}
return nil
}
}

var testAccNomadProviderConfigWithHeaders = `
provider "nomad" {
headers {
Expand All @@ -180,6 +208,31 @@ provider "nomad" {
data "nomad_namespaces" "test" {}
`

var testAccNomadProviderConfigWithHeadersCrash = `
provider "nomad" {
headers {
name = "Test-Header-1"
value = "a"
}
headers {
name = "Test-header-1"
value = "b"
}
headers {
name = "test-header-2"
value = "c"
}
}
// necessary to initialize the provider
data "nomad_namespaces" "test" {}
resource "nomad_namespace" "test" {
count = 100
name = "headers-crash-test-${count.index}"
}
`

func TestAccNomadProvider_ConsulToken(t *testing.T) {
var provider *schema.Provider

Expand Down

0 comments on commit ff82981

Please sign in to comment.