Skip to content

Commit 38e8932

Browse files
committed
test: execute all tests in parallel and override HTTP client
1 parent f680e68 commit 38e8932

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,8 @@ jobs:
2222
run: go test -tags=unit -v ./...
2323

2424
integration-tests:
25-
name: Integration Tests - ${{ matrix.config.name }}
25+
name: Integration Tests
2626
runs-on: ubuntu-latest
27-
strategy:
28-
fail-fast: false
29-
matrix:
30-
# several tests are split into chunks with about 20 tests
31-
# A dynamic matrix can't be used because there is a limit of 256 entries
32-
config:
33-
- { name: "app", path: "./dynatrace/api/app/..." }
34-
- { name: "automation", path: "./dynatrace/api/automation/..." }
35-
- { name: "cluster", path: "./dynatrace/api/cluster/..." }
36-
- { name: "documents", path: "./dynatrace/api/documents/..." }
37-
- { name: "grail", path: "./dynatrace/api/grail/..." }
38-
- { name: "iam", path: "./dynatrace/api/iam/..." }
39-
- { name: "openpipeline", path: "./dynatrace/api/openpipeline/..." }
40-
- { name: "platform", path: "./dynatrace/api/platform/..." }
41-
- { name: "service", path: "./dynatrace/api/service/..." }
42-
- { name: "slo", path: "./dynatrace/api/slo/..." }
43-
- { name: "v1 (a-d)", path: "$(go list ./dynatrace/api/v1/... | grep -E '^.+/dynatrace/api/v1/[a-d][^/]*/?')" }
44-
- { name: "v1 (e-z)", path: "$(go list ./dynatrace/api/v1/... | grep -E '^.+/dynatrace/api/v1/[e-z][^/]*/?')" }
45-
- { name: "v2", path: "./dynatrace/api/v2/..." }
46-
- { name: "builtin (a-b)", path: "$(go list ./dynatrace/api/builtin/... | grep -E '^.+/dynatrace/api/builtin/[a-b][^/]*/?')" }
47-
- { name: "builtin (c-e)", path: "$(go list ./dynatrace/api/builtin/... | grep -E '^.+/dynatrace/api/builtin/[c-e][^/]*/?')" }
48-
- { name: "builtin (f-m)", path: "$(go list ./dynatrace/api/builtin/... | grep -E '^.+/dynatrace/api/builtin/[f-m][^/]*/?')" }
49-
- { name: "builtin (n-o)", path: "$(go list ./dynatrace/api/builtin/... | grep -E '^.+/dynatrace/api/builtin/[n-o][^/]*/?')" }
50-
- { name: "builtin (p-s)", path: "$(go list ./dynatrace/api/builtin/... | grep -E '^.+/dynatrace/api/builtin/[p-s][^/]*/?')" }
51-
- { name: "builtin (t-z)", path: "$(go list ./dynatrace/api/builtin/... | grep -E '^.+/dynatrace/api/builtin/[t-z][^/]*/?')" }
5227
steps:
5328
- name: Set up Go
5429
uses: actions/setup-go@19bb51245e9c80abacb2e91cc42b33fa478b8639 # 4.2.1
@@ -62,7 +37,7 @@ jobs:
6237
with:
6338
terraform_wrapper: false
6439

65-
- name: Run Integration Tests - ${{ matrix.config.name }}
40+
- name: Run Integration Tests
6641
if: success() || failure()
6742
env:
6843
GOPROXY: "https://proxy.golang.org"
@@ -75,4 +50,4 @@ jobs:
7550
DT_CLIENT_ID: ${{ secrets.DT_CLIENT_ID }}
7651
DT_CLIENT_SECRET: ${{ secrets.DT_CLIENT_SECRET }}
7752
DT_ACCOUNT_ID: ${{ secrets.DT_ACCOUNT_ID }}
78-
run: go test -tags=integration -v -p 1 ${{ matrix.config.path }}
53+
run: go test -tags=integration -v ./...

dynatrace/rest/platform_request.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
"regexp"
1010
"strings"
1111
"sync"
12+
"time"
1213

1314
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/rest/logging"
1415
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/version"
16+
"golang.org/x/oauth2"
1517
"golang.org/x/oauth2/clientcredentials"
1618

1719
"github.com/dynatrace/dynatrace-configuration-as-code-core/api/auth"
@@ -49,6 +51,16 @@ func configureCommonRestClient(restClient *rest.Client) (*rest.Client, error) {
4951
return restClient, nil
5052
}
5153

54+
func setHttpClientContext(ctx context.Context) context.Context {
55+
return context.WithValue(ctx, oauth2.HTTPClient, &http.Client{
56+
Transport: &http.Transport{
57+
MaxIdleConns: 100,
58+
MaxIdleConnsPerHost: 100,
59+
IdleConnTimeout: 90 * time.Second,
60+
},
61+
})
62+
}
63+
5264
func CreatePlatformOAuthClient(ctx context.Context, u string, credentials *Credentials) (*rest.Client, error) {
5365
parsedURL, err := url.Parse(u)
5466
if err != nil {
@@ -59,6 +71,7 @@ func CreatePlatformOAuthClient(ctx context.Context, u string, credentials *Crede
5971
ClientSecret: credentials.OAuth.ClientSecret,
6072
TokenURL: evalTokenURL(parsedURL.String()),
6173
}
74+
ctx = setHttpClientContext(ctx)
6275
httpClient := auth.NewOAuthClient(ctx, &oauthConfig)
6376

6477
opts := []rest.Option{

0 commit comments

Comments
 (0)