From d216d4df3aa9b30188570deb27d42af224d4f085 Mon Sep 17 00:00:00 2001 From: Eric Leijonmarck Date: Wed, 8 Mar 2023 11:45:01 +0000 Subject: [PATCH 1/2] tests with MaxConnsPerHost --- internal/provider/provider.go | 1 + .../grafana/resource_service_account_test.go | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 74718bc6d..378fd007e 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -340,6 +340,7 @@ func createGrafanaClient(d *schema.ResourceData) (string, *gapi.Config, *gapi.Cl auth := strings.SplitN(d.Get("auth").(string), ":", 2) cli := cleanhttp.DefaultClient() transport := cleanhttp.DefaultTransport() + transport.MaxConnsPerHost = 2 transport.TLSClientConfig = &tls.Config{} // TLS Config diff --git a/internal/resources/grafana/resource_service_account_test.go b/internal/resources/grafana/resource_service_account_test.go index cb5f87580..f1e6cb327 100644 --- a/internal/resources/grafana/resource_service_account_test.go +++ b/internal/resources/grafana/resource_service_account_test.go @@ -40,6 +40,27 @@ func TestAccServiceAccount_basic(t *testing.T) { }) } +func TestAccServiceAccount_many(t *testing.T) { + testutils.CheckOSSTestsEnabled(t) + testutils.CheckOSSTestsSemver(t, ">=9.1.0") + + name := acctest.RandString(10) + + resource.ParallelTest(t, resource.TestCase{ + ProviderFactories: testutils.ProviderFactories, + CheckDestroy: testAccServiceAccountCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testManyServiceAccountsConfig(name, 60), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("grafana_service_account.test_1", "name", name+"-1"), + resource.TestCheckResourceAttr("grafana_service_account.test_2", "name", name+"-2"), + ), + }, + }, + }) +} + func TestAccServiceAccount_invalid_role(t *testing.T) { testutils.CheckOSSTestsEnabled(t) @@ -55,6 +76,22 @@ func TestAccServiceAccount_invalid_role(t *testing.T) { }) } +func testManyServiceAccountsConfig(prefix string, count int) string { + config := `` + + for i := 0; i < count; i++ { + config += fmt.Sprintf(` + resource "grafana_service_account" "test_%[2]d" { + name = "%[1]s-%[2]d" + is_disabled = false + role = "Viewer" + } +`, prefix, i) + } + + return config +} + func testAccServiceAccountCheckExists(s *terraform.State) error { return testAccServiceAccountCheckExistsBool(s, true) } From de4bf52735fff0c035c1a88bb35cacf28d99aca2 Mon Sep 17 00:00:00 2001 From: Eric Leijonmarck Date: Wed, 8 Mar 2023 13:01:07 +0000 Subject: [PATCH 2/2] add comment --- internal/provider/provider.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 378fd007e..efc09d568 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -340,8 +340,10 @@ func createGrafanaClient(d *schema.ResourceData) (string, *gapi.Config, *gapi.Cl auth := strings.SplitN(d.Get("auth").(string), ":", 2) cli := cleanhttp.DefaultClient() transport := cleanhttp.DefaultTransport() - transport.MaxConnsPerHost = 2 transport.TLSClientConfig = &tls.Config{} + // limiting the amount of concurrent HTTP connections from the provider + // makes it not overload the API and DB + transport.MaxConnsPerHost = 2 // TLS Config tlsKey := d.Get("tls_key").(string)