Skip to content

Commit 3d692f2

Browse files
Increase timeouts (#311)
Co-authored-by: Fabian Jakobs <fabian.jakobs@databricks.com>
1 parent 6463123 commit 3d692f2

File tree

4 files changed

+147
-92
lines changed

4 files changed

+147
-92
lines changed

packages/databricks-vscode/src/test/e2e/configure.e2e.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from "node:path";
33
import * as fs from "fs/promises";
44
import {
55
getViewSection,
6-
waitForPythonExtension,
6+
waitForPythonExtensionWithRetry,
77
waitForTreeItems,
88
} from "./utils";
99
import {
@@ -21,7 +21,7 @@ describe("Configure Databricks Extension", async function () {
2121
let host: string;
2222
let workbench: Workbench;
2323

24-
this.timeout(3 * 60 * 1000);
24+
this.timeout(5 * 60 * 1000);
2525

2626
before(async function () {
2727
assert(
@@ -41,7 +41,7 @@ describe("Configure Databricks Extension", async function () {
4141
host = process.env.DATABRICKS_HOST;
4242

4343
workbench = await browser.getWorkbench();
44-
await waitForPythonExtension();
44+
await waitForPythonExtensionWithRetry(1.5 * 60 * 1000, 2);
4545
});
4646

4747
it("should open VSCode", async function () {

packages/databricks-vscode/src/test/e2e/run_job_on_cluster.e2e.ts

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import * as fs from "fs/promises";
33
import assert from "node:assert";
44
import {
55
getViewSection,
6-
getViewSubSection,
7-
waitForPythonExtension,
8-
waitForTreeItems,
6+
startSyncIfStopped,
7+
waitForPythonExtensionWithRetry,
8+
waitForSyncComplete,
99
} from "./utils";
10-
import {sleep, TreeItem} from "wdio-vscode-service";
10+
import {sleep} from "wdio-vscode-service";
1111

12-
describe("Run python on cluster", async function () {
12+
describe("Run as workflow on cluster", async function () {
1313
let projectDir: string;
14-
this.timeout(2 * 60 * 1000);
14+
this.timeout(5 * 60 * 1000);
1515

1616
before(async () => {
1717
assert(process.env.TEST_DEFAULT_CLUSTER_ID);
@@ -42,59 +42,15 @@ describe("Run python on cluster", async function () {
4242
].join("\n")
4343
);
4444

45-
const section = await getViewSection("CONFIGURATION");
46-
assert(section);
47-
await waitForTreeItems(section);
48-
await waitForPythonExtension();
45+
await waitForPythonExtensionWithRetry(1.5 * 60 * 1000, 2);
46+
47+
await (await getViewSection("CLUSTERS"))?.collapse();
4948
});
5049

5150
beforeEach(async () => {
52-
const section = await getViewSection("CLUSTERS");
53-
await section?.collapse();
54-
55-
const repoConfigItem = await getViewSubSection("CONFIGURATION", "Repo");
56-
assert(repoConfigItem);
51+
await startSyncIfStopped();
5752

58-
let status: TreeItem | undefined = undefined;
59-
for (const i of await repoConfigItem.getChildren()) {
60-
if ((await i.getLabel()).includes("State:")) {
61-
status = i;
62-
break;
63-
}
64-
}
65-
assert(status);
66-
if ((await status.getDescription())?.includes("STOPPED")) {
67-
const buttons = await repoConfigItem.getActionButtons();
68-
await buttons[0].elem.click();
69-
}
70-
71-
await browser.waitUntil(
72-
async () => {
73-
const repoConfigItem = await getViewSubSection(
74-
"CONFIGURATION",
75-
"Repo"
76-
);
77-
assert(repoConfigItem);
78-
79-
status = undefined;
80-
for (const i of await repoConfigItem.getChildren()) {
81-
if ((await i.getLabel()).includes("State:")) {
82-
status = i;
83-
break;
84-
}
85-
}
86-
assert(status);
87-
const description = await status?.getDescription();
88-
return (
89-
description !== undefined &&
90-
description.includes("WATCHING_FOR_CHANGES")
91-
);
92-
},
93-
{
94-
timeout: 20000,
95-
timeoutMsg: "Couldn't finish sync in 20s",
96-
}
97-
);
53+
await waitForSyncComplete();
9854
});
9955

10056
it("should run a python notebook as a job on a cluster", async () => {
@@ -170,7 +126,7 @@ describe("Run python on cluster", async function () {
170126
await sleep(200);
171127
await input.setText("file.py");
172128
await input.confirm();
173-
await sleep(500);
129+
await sleep(2000);
174130

175131
// run file
176132
await workbench.executeQuickPick(

packages/databricks-vscode/src/test/e2e/run_on_cluster.e2e.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import * as fs from "fs/promises";
33
import assert from "node:assert";
44
import {
55
getViewSection,
6-
getViewSubSection,
7-
waitForPythonExtension,
6+
startSyncIfStopped,
7+
waitForPythonExtensionWithRetry,
8+
waitForSyncComplete,
89
waitForTreeItems,
910
} from "./utils";
1011
import {sleep} from "wdio-vscode-service";
1112

1213
describe("Run python on cluster", async function () {
1314
let projectDir: string;
14-
this.timeout(3 * 60 * 1000);
15+
this.timeout(5 * 60 * 1000);
1516

1617
before(async () => {
1718
assert(process.env.DATABRICKS_HOST);
@@ -36,7 +37,7 @@ describe("Run python on cluster", async function () {
3637
path.join(projectDir, "hello.py"),
3738
`spark.sql('SELECT "hello world"').show()`
3839
);
39-
await waitForPythonExtension();
40+
await waitForPythonExtensionWithRetry(1.5 * 60 * 1000, 2);
4041
});
4142

4243
it("should connect to Databricks", async () => {
@@ -49,22 +50,10 @@ describe("Run python on cluster", async function () {
4950
const section = await getViewSection("CLUSTERS");
5051
await section?.collapse();
5152

52-
const repoConfigItem = await getViewSubSection("CONFIGURATION", "Repo");
53-
assert(repoConfigItem);
54-
const buttons = await repoConfigItem.getActionButtons();
55-
await buttons[0].elem.click();
53+
await startSyncIfStopped();
5654

5755
// wait for sync to finish
58-
const workbench = await driver.getWorkbench();
59-
const terminalView = await workbench.getBottomBar().openTerminalView();
60-
61-
while (true) {
62-
await sleep(500);
63-
const text = await terminalView.getText();
64-
if (text.includes("Sync Complete")) {
65-
break;
66-
}
67-
}
56+
await waitForSyncComplete();
6857
});
6958

7059
it("should run a python file on a cluster", async () => {

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

Lines changed: 125 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,34 @@ export async function waitForTreeItems(
8282
}
8383
}
8484

85-
export async function waitForPythonExtension() {
85+
export async function waitForPythonExtension(timeoutMs: number) {
8686
const section = await getViewSection("CONFIGURATION");
8787
assert(section);
88-
const welcome = await section.findWelcomeContent();
89-
assert(welcome);
90-
sleep(1000);
9188
const workbench = await browser.getWorkbench();
92-
const notifs = await workbench.getNotifications();
93-
for (const n of notifs) {
94-
if (
95-
(await n.getActions()).find(
96-
(btn) => btn.getTitle() === "Install and Reload"
97-
) !== undefined
98-
) {
99-
await n.takeAction("Install and Reload");
89+
90+
await browser.waitUntil(
91+
async () => {
92+
const notifs = await workbench.getNotifications();
93+
let found = false;
94+
for (const n of notifs) {
95+
if (
96+
(await n.getActions()).find(
97+
(btn) => btn.getTitle() === "Install and Reload"
98+
) !== undefined
99+
) {
100+
await n.takeAction("Install and Reload");
101+
found = true;
102+
}
103+
}
104+
return found;
105+
},
106+
{
107+
timeout: 5 * 1000,
108+
interval: 500,
109+
timeoutMsg:
110+
"Can't find notification to install ms-python extension",
100111
}
101-
}
112+
);
102113

103114
await browser.waitUntil(
104115
async () =>
@@ -108,16 +119,115 @@ export async function waitForPythonExtension() {
108119
)?.getTitle()
109120
)?.includes("README.quickstart.md") === true,
110121
{
111-
timeout: 120000,
122+
timeout: timeoutMs,
112123
timeoutMsg:
113124
"Timeout when installing python extension and reloading",
114125
}
115126
);
116127

117-
sleep(500);
128+
await sleep(500);
118129
try {
130+
const notifs = await workbench.getNotifications();
119131
for (const n of notifs) {
120132
await n.dismiss();
121133
}
122134
} catch {}
123135
}
136+
137+
export async function waitForPythonExtensionWithRetry(
138+
timeoutMs: number,
139+
retryCount: number
140+
) {
141+
for (let i = 0; i < retryCount; i++) {
142+
try {
143+
const section = await getViewSection("CONFIGURATION");
144+
assert(section);
145+
await waitForPythonExtension(timeoutMs);
146+
} catch (e) {
147+
// eslint-disable-next-line no-console
148+
console.error(e);
149+
const wb = await browser.getWorkbench();
150+
await wb.executeCommand("Developer: Reload Window");
151+
if (i === retryCount - 1) {
152+
throw e;
153+
}
154+
continue;
155+
}
156+
break;
157+
}
158+
}
159+
160+
export async function waitForSyncComplete() {
161+
await browser.waitUntil(
162+
async () => {
163+
const repoConfigItem = await getViewSubSection(
164+
"CONFIGURATION",
165+
"Repo"
166+
);
167+
if (repoConfigItem === undefined) {
168+
return false;
169+
}
170+
await repoConfigItem.expand();
171+
172+
let status: TreeItem | undefined = undefined;
173+
for (const i of await repoConfigItem.getChildren()) {
174+
if ((await i.getLabel()).includes("State:")) {
175+
status = i;
176+
break;
177+
}
178+
}
179+
if (status === undefined) {
180+
return false;
181+
}
182+
183+
const description = await status?.getDescription();
184+
return (
185+
description !== undefined &&
186+
description.includes("WATCHING_FOR_CHANGES")
187+
);
188+
},
189+
{
190+
timeout: 60000,
191+
interval: 20000,
192+
timeoutMsg: "Couldn't finish sync in 1m",
193+
}
194+
);
195+
}
196+
197+
export async function startSyncIfStopped() {
198+
browser.waitUntil(
199+
async () => {
200+
const repoConfigItem = await getViewSubSection(
201+
"CONFIGURATION",
202+
"Repo"
203+
);
204+
if (repoConfigItem === undefined) {
205+
return false;
206+
}
207+
await repoConfigItem.expand();
208+
209+
let status: TreeItem | undefined = undefined;
210+
for (const i of await repoConfigItem.getChildren()) {
211+
if ((await i.getLabel()).includes("State:")) {
212+
status = i;
213+
break;
214+
}
215+
}
216+
if (status === undefined) {
217+
return false;
218+
}
219+
220+
if ((await status.getDescription())?.includes("STOPPED")) {
221+
const buttons = await repoConfigItem.getActionButtons();
222+
if (buttons.length === 0) {
223+
return false;
224+
}
225+
await buttons[0].elem.click();
226+
}
227+
return true;
228+
},
229+
{
230+
timeout: 20000,
231+
}
232+
);
233+
}

0 commit comments

Comments
 (0)