Skip to content

Commit 4a5db6c

Browse files
committed
WIP: add serverless e2e tests
1 parent 8e24c87 commit 4a5db6c

File tree

4 files changed

+85
-13
lines changed

4 files changed

+85
-13
lines changed

packages/databricks-vscode/scripts/list_integration_tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const integrationTests = glob
2121
return {
2222
path: toUnixPath(path.relative(process.cwd(), testPath)),
2323
baseName: path.basename(testPath, ".e2e.ts"),
24+
serverless: testPath.includes("serverless") ? true : false,
2425
};
2526
});
2627

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import path from "node:path";
2+
import * as fs from "fs/promises";
3+
import assert from "node:assert";
4+
import {
5+
dismissNotifications,
6+
executeCommandWhenAvailable,
7+
openFile,
8+
waitForLogin,
9+
waitForWorkflowWebview,
10+
} from "./utils/commonUtils.ts";
11+
import {sleep} from "wdio-vscode-service";
12+
import {
13+
getBasicBundleConfig,
14+
writeRootBundleConfig,
15+
} from "./utils/dabsFixtures.ts";
16+
17+
describe("Run files on serverless compute", async function () {
18+
let projectDir: string;
19+
this.timeout(3 * 60 * 1000);
20+
21+
before(async () => {
22+
assert(process.env.WORKSPACE_PATH, "WORKSPACE_PATH doesn't exist");
23+
24+
projectDir = process.env.WORKSPACE_PATH;
25+
26+
await fs.writeFile(
27+
path.join(projectDir, "lib.py"),
28+
[
29+
"def func(spark):",
30+
`\tspark.sql('SELECT "hello world"').show()`,
31+
].join("\n")
32+
);
33+
const nestedDir = path.join(projectDir, "nested");
34+
await fs.mkdir(nestedDir, {recursive: true});
35+
await fs.writeFile(
36+
path.join(nestedDir, "hello.py"),
37+
[`from lib import func`, "func(spark)"].join("\n")
38+
);
39+
40+
await writeRootBundleConfig(
41+
getBasicBundleConfig({}, false),
42+
projectDir
43+
);
44+
await waitForLogin("DEFAULT");
45+
await dismissNotifications();
46+
});
47+
48+
beforeEach(async () => {
49+
await openFile("hello.py");
50+
});
51+
52+
it("should run a python file as a serverless workflow", async () => {
53+
await executeCommandWhenAvailable("Databricks: Run File as Workflow");
54+
await waitForWorkflowWebview("hello world");
55+
});
56+
});

packages/databricks-vscode/src/test/e2e/utils/dabsFixtures.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ export function getBasicBundleConfig(
6060
topLevelComputeId = true
6161
): BundleSchema {
6262
assert(process.env.DATABRICKS_HOST, "DATABRICKS_HOST doesn't exist");
63-
assert(
64-
process.env.TEST_DEFAULT_CLUSTER_ID,
65-
"TEST_DEFAULT_CLUSTER_ID doesn't exist"
66-
);
63+
if (!topLevelComputeId) {
64+
assert(
65+
process.env.TEST_DEFAULT_CLUSTER_ID,
66+
"TEST_DEFAULT_CLUSTER_ID doesn't exist"
67+
);
68+
}
6769
/* eslint-disable @typescript-eslint/naming-convention */
6870
const defaultBundleConfig = {
6971
bundle: {

packages/databricks-vscode/src/test/e2e/wdio.conf.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,10 @@ export const config: Options.Testrunner = {
315315
await config.ensureResolved();
316316

317317
assert(config.host, "Config host must be set");
318-
assert(config.token, "Config token must be set");
318+
assert(
319+
config.token || (config.clientId && config.clientSecret),
320+
"Config must have a token or a clientId with clientSecret"
321+
);
319322

320323
assert(
321324
process.env["TEST_DEFAULT_CLUSTER_ID"],
@@ -326,8 +329,13 @@ export const config: Options.Testrunner = {
326329
console.log(`Creating vscode workspace folder: ${WORKSPACE_PATH}`);
327330
await fs.mkdir(WORKSPACE_PATH, {recursive: true});
328331

329-
const client = getWorkspaceClient(config);
330-
await startCluster(client, process.env["TEST_DEFAULT_CLUSTER_ID"]);
332+
if (config.token) {
333+
const client = getWorkspaceClient(config);
334+
await startCluster(
335+
client,
336+
process.env["TEST_DEFAULT_CLUSTER_ID"]
337+
);
338+
}
331339

332340
process.env.DATABRICKS_HOST = config.host!;
333341
process.env.DATABRICKS_VSCODE_INTEGRATION_TEST = "true";
@@ -599,12 +607,17 @@ export const config: Options.Testrunner = {
599607

600608
async function writeDatabricksConfig(config: Config, rootPath: string) {
601609
const configFile = path.join(rootPath, ".databrickscfg");
602-
await fs.writeFile(
603-
configFile,
604-
`[DEFAULT]
605-
host = ${config.host!}
606-
token = ${config.token!}`
607-
);
610+
let content = "[DEFAULT]\n";
611+
if (config.token) {
612+
content += `host = ${config.host!}\n`;
613+
content += `token = ${config.token!}\n`;
614+
} else {
615+
content += `host = ${config.host!}\n`;
616+
content += `client_id = ${config.clientId!}\n`;
617+
content += `client_secret = ${config.clientSecret!}\n`;
618+
content += `serverless_compute_id = auto\n`;
619+
}
620+
await fs.writeFile(configFile, content);
608621
return configFile;
609622
}
610623

0 commit comments

Comments
 (0)