Skip to content

Commit 419e53f

Browse files
authored
Parametrize acceptance action with pytest parallel worker count (#730)
## Summary - Add a new `n` input to the acceptance GitHub Action (default `10`) for configuring pytest-xdist parallel workers. Propagates via the `PYTEST_N` env var to `pytest_run.py`; Go tests are unaffected. - Updated depreciated sdk methods to fix `make fmt` ## Test plan - [x] `make fmt` passes locally - [x] `make test` passes locally - [x] Run the action in a downstream repo with `n: '4'` and confirm pytest uses `-n 4` - [x] Run the action without setting `n` and confirm default of `10` Context: we need to be able to reduce parallel test execution in DQX as 10 parallel runs creates a high contention of testing clusters. This would require a new release.
1 parent 19329ed commit 419e53f

6 files changed

Lines changed: 14 additions & 5 deletions

File tree

acceptance/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ inputs:
2727
codegen_path:
2828
description: 'Relative path to the .codegen.json file to use for configuring the acceptance tests'
2929
required: false # by default the first .codegen.json found in the project is used
30+
n:
31+
description: 'Number of parallel pytest workers (pytest-xdist -n).'
32+
required: false
33+
default: '10'
3034
outputs:
3135
sample:
3236
description: 'Sample output'

acceptance/ecosystem/pytest_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def pytest_runtest_logreport(self, report: pytest.TestReport):
4949

5050
if __name__ == '__main__':
5151
sys.exit(pytest.main([
52-
'-n', '10',
52+
'-n', (os.environ.get('PYTEST_N') or '').strip() or '10',
5353
"--log-disable", "urllib3.connectionpool",
5454
"--log-format", "%(asctime)s %(levelname)s [%(name)s] %(message)s",
5555
"--log-date-format", "%H:%M",

acceptance/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func (a *acceptance) trigger(ctx context.Context) (*notify.Notification, error)
7171
// set codegen path file used for configuring the acceptance tests
7272
codegenPath := a.Action.GetInput("codegen_path")
7373
ctx = env.Set(ctx, "codegen_path", codegenPath)
74+
if n := a.Action.GetInput("n"); n != "" {
75+
ctx = env.Set(ctx, "PYTEST_N", n)
76+
}
7477
redact := loaded.Redaction()
7578
report, err := a.runWithTimeout(ctx, redact, directory)
7679
if err != nil {

acceptance/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func TestXxx(t *testing.T) {
1212
t.Skip()
1313
ctx := context.Background()
1414
ctx = env.Set(ctx, "INPUT_DIRECTORY", "../go-libs")
15+
ctx = env.Set(ctx, "INPUT_N", "4") // verify PYTEST_N=4 in pytest output
1516
err := run(ctx)
1617
assert.NoError(t, err)
1718
}

acceptance/testenv/githubOidc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (cpf *credentialsProviderFunc) SetHeaders(r *http.Request) error {
7373

7474
// Configure implements credentials provider for Databricks SDK
7575
func (c *ghOidcCreds) Configure(ctx context.Context, cfg *config.Config) (credentials.CredentialsProvider, error) {
76-
ts, err := c.oidcTokenSource(ctx, cfg.Environment().AzureApplicationID)
76+
ts, err := c.oidcTokenSource(ctx, environment.GetEnvironmentForHostname(cfg.CanonicalHostName()).AzureApplicationID)
7777
if err != nil {
7878
return nil, fmt.Errorf("oidc: %w", err)
7979
}

acceptance/testenv/loaded.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (l *loadedEnv) Cloud() environment.Cloud {
7171
if err != nil {
7272
return environment.CloudAWS
7373
}
74-
return cfg.Environment().Cloud
74+
return environment.GetEnvironmentForHostname(cfg.CanonicalHostName()).Cloud
7575
}
7676

7777
func (l *loadedEnv) Start(ctx context.Context) (context.Context, func(), error) {
@@ -80,7 +80,8 @@ func (l *loadedEnv) Start(ctx context.Context) (context.Context, func(), error)
8080
return nil, nil, fmt.Errorf("config: %w", err)
8181
}
8282
srv := l.metadataServer(cfg)
83-
ctx = env.Set(ctx, "CLOUD_ENV", strings.ToLower(string(cfg.Environment().Cloud)))
83+
cloud := environment.GetEnvironmentForHostname(cfg.CanonicalHostName()).Cloud
84+
ctx = env.Set(ctx, "CLOUD_ENV", strings.ToLower(string(cloud)))
8485
ctx = env.Set(ctx, "DATABRICKS_METADATA_SERVICE_URL", fmt.Sprintf("%s/%s", srv.URL, l.mpath))
8586
ctx = env.Set(ctx, "DATABRICKS_AUTH_TYPE", "metadata-service")
8687
isAuth := map[string]bool{}
@@ -104,7 +105,7 @@ func (l *loadedEnv) Start(ctx context.Context) (context.Context, func(), error)
104105
}
105106

106107
func (l *loadedEnv) metadataServer(seed *config.Config) *httptest.Server {
107-
accountHost := seed.Environment().DeploymentURL("accounts")
108+
accountHost := environment.GetEnvironmentForHostname(seed.CanonicalHostName()).DeploymentURL("accounts")
108109
configurations := map[string]*config.Config{
109110
seed.CanonicalHostName(): seed,
110111
accountHost: {

0 commit comments

Comments
 (0)