Skip to content

Commit 97410e5

Browse files
authored
Provider: MaxConnsPerHost tests with creating 60 service accounts (#842)
* tests with MaxConnsPerHost * add comment
1 parent 91451de commit 97410e5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

internal/provider/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ func createGrafanaClient(d *schema.ResourceData) (string, *gapi.Config, *gapi.Cl
341341
cli := cleanhttp.DefaultClient()
342342
transport := cleanhttp.DefaultTransport()
343343
transport.TLSClientConfig = &tls.Config{}
344+
// limiting the amount of concurrent HTTP connections from the provider
345+
// makes it not overload the API and DB
346+
transport.MaxConnsPerHost = 2
344347

345348
// TLS Config
346349
tlsKey := d.Get("tls_key").(string)

internal/resources/grafana/resource_service_account_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ func TestAccServiceAccount_basic(t *testing.T) {
4040
})
4141
}
4242

43+
func TestAccServiceAccount_many(t *testing.T) {
44+
testutils.CheckOSSTestsEnabled(t)
45+
testutils.CheckOSSTestsSemver(t, ">=9.1.0")
46+
47+
name := acctest.RandString(10)
48+
49+
resource.ParallelTest(t, resource.TestCase{
50+
ProviderFactories: testutils.ProviderFactories,
51+
CheckDestroy: testAccServiceAccountCheckDestroy,
52+
Steps: []resource.TestStep{
53+
{
54+
Config: testManyServiceAccountsConfig(name, 60),
55+
Check: resource.ComposeTestCheckFunc(
56+
resource.TestCheckResourceAttr("grafana_service_account.test_1", "name", name+"-1"),
57+
resource.TestCheckResourceAttr("grafana_service_account.test_2", "name", name+"-2"),
58+
),
59+
},
60+
},
61+
})
62+
}
63+
4364
func TestAccServiceAccount_invalid_role(t *testing.T) {
4465
testutils.CheckOSSTestsEnabled(t)
4566

@@ -55,6 +76,22 @@ func TestAccServiceAccount_invalid_role(t *testing.T) {
5576
})
5677
}
5778

79+
func testManyServiceAccountsConfig(prefix string, count int) string {
80+
config := ``
81+
82+
for i := 0; i < count; i++ {
83+
config += fmt.Sprintf(`
84+
resource "grafana_service_account" "test_%[2]d" {
85+
name = "%[1]s-%[2]d"
86+
is_disabled = false
87+
role = "Viewer"
88+
}
89+
`, prefix, i)
90+
}
91+
92+
return config
93+
}
94+
5895
func testAccServiceAccountCheckExists(s *terraform.State) error {
5996
return testAccServiceAccountCheckExistsBool(s, true)
6097
}

0 commit comments

Comments
 (0)