Skip to content

Commit 9aef719

Browse files
authored
Hide "create" quick pick items when filter is applied (#189)
- Hide "create" quick pick items when filter is applied - Replace chai with sinon and fake timer for retry unit tests - teast are running in a few ms new instead of in 8 seconds.
1 parent 613e8f1 commit 9aef719

7 files changed

Lines changed: 197 additions & 160 deletions

File tree

packages/databricks-sdk-js/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,17 @@
3636
},
3737
"devDependencies": {
3838
"@istanbuljs/nyc-config-typescript": "^1.0.2",
39-
"@types/chai": "^4.3.3",
40-
"@types/chai-as-promised": "^7.1.5",
41-
"@types/chai-spies": "^1.0.3",
4239
"@types/ini": "^1.3.31",
4340
"@types/mocha": "^10.0.0",
4441
"@types/node": "^18.11.9",
42+
"@types/sinon": "^10.0.13",
4543
"@types/tmp": "^0.2.3",
4644
"@types/uuid": "^8.3.4",
47-
"chai": "^4.3.6",
48-
"chai-as-promised": "^7.1.1",
49-
"chai-spies": "^1.0.0",
5045
"eslint": "^8.26.0",
5146
"mocha": "^10.1.0",
5247
"nyc": "^15.1.0",
5348
"prettier": "^2.7.1",
49+
"sinon": "^14.0.2",
5450
"tmp-promise": "^3.0.3",
5551
"ts-loader": "^9.4.1",
5652
"ts-mocha": "^10.0.0",
Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import retry, {RetriableError, TimeoutError} from "./retries";
22
import Time, {TimeUnits} from "./Time";
3-
import chai, {assert, expect} from "chai";
4-
import spies from "chai-spies";
5-
import chaiAsPromised from "chai-as-promised";
3+
import * as sinon from "sinon";
4+
import * as assert from "node:assert";
65

7-
chai.use(chaiAsPromised);
8-
chai.use(spies);
96
class NonRetriableError extends Error {}
107

118
describe(__filename, function () {
12-
this.timeout(new Time(10, TimeUnits.minutes).toMillSeconds().value);
9+
let fakeTimer: sinon.SinonFakeTimers;
1310

11+
beforeEach(() => {
12+
fakeTimer = sinon.useFakeTimers();
13+
});
14+
15+
afterEach(() => {
16+
fakeTimer.restore();
17+
});
18+
19+
this.timeout(1000 * 3);
1420
it("should return result if timeout doesn't expire", async function () {
1521
const startTime = Date.now();
1622

17-
const retryResult = await retry({
23+
const retryResult = retry({
1824
timeout: new Time(5, TimeUnits.seconds),
1925
fn: () => {
2026
if (Date.now() - startTime < 1000) {
@@ -26,39 +32,57 @@ describe(__filename, function () {
2632
},
2733
});
2834

29-
assert.equal(retryResult, "returned_string");
35+
fakeTimer.tick(800);
36+
fakeTimer.tick(800);
37+
fakeTimer.tick(800);
38+
39+
assert.equal(await retryResult, "returned_string");
3040
});
3141

3242
it("should return retriable error if timeout expires", async function () {
3343
const startTime = Date.now();
34-
await expect(
35-
retry({
36-
timeout: new Time(5, TimeUnits.seconds),
37-
fn: () => {
38-
if (Date.now() - startTime < 10000) {
39-
throw new RetriableError();
40-
}
41-
return new Promise<string>((resolve) =>
42-
resolve("returned_string")
43-
);
44-
},
45-
})
46-
).to.be.rejectedWith(TimeoutError);
44+
45+
const retryResult = retry({
46+
timeout: new Time(5, TimeUnits.seconds),
47+
fn: () => {
48+
if (Date.now() - startTime < 10000) {
49+
throw new RetriableError();
50+
}
51+
return new Promise<string>((resolve) =>
52+
resolve("returned_string")
53+
);
54+
},
55+
});
56+
57+
fakeTimer.tick(800);
58+
fakeTimer.tick(800);
59+
fakeTimer.tick(2000);
60+
fakeTimer.tick(5000);
61+
62+
try {
63+
await retryResult;
64+
assert.fail("should throw TimeoutError");
65+
} catch (err) {
66+
assert.ok(err instanceof TimeoutError);
67+
}
4768
});
4869

4970
it("should throw non retriable error immediately", async function () {
50-
const mockFunction = chai.spy();
71+
let callCount = 0;
5172

52-
await expect(
53-
retry({
73+
try {
74+
await retry({
5475
timeout: new Time(5, TimeUnits.seconds),
5576
fn: () => {
56-
mockFunction();
77+
callCount += 1;
5778
throw new NonRetriableError();
5879
},
59-
})
60-
).to.be.rejectedWith(NonRetriableError);
80+
});
81+
assert.fail("should throw NonRetriableError");
82+
} catch (err) {
83+
assert.ok(err instanceof NonRetriableError);
84+
}
6185

62-
expect(mockFunction).to.be.called.once;
86+
assert.equal(callCount, 1);
6387
});
6488
});

packages/databricks-sdk-js/src/services/Cluster.integ.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
22

33
import {Cluster} from "..";
4-
import assert from "assert";
5-
import chai from "chai";
6-
import chaiAsPromised from "chai-as-promised";
4+
import assert from "node:assert";
75
import {IntegrationTestSetup} from "../test/IntegrationTestSetup";
86

9-
chai.use(chaiAsPromised);
10-
117
describe(__filename, function () {
128
let integSetup: IntegrationTestSetup;
139

packages/databricks-sdk-js/src/services/Cluster.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
22

33
import {ApiClient, Cluster} from "..";
4-
import chai, {assert} from "chai";
4+
import * as assert from "node:assert";
55
import {mock, when, instance, deepEqual, verify, anything} from "ts-mockito";
6-
import chaiAsPromised from "chai-as-promised";
76
import Time, {TimeUnits} from "../retries/Time";
87
import {getMockTestCluster} from "../test/fixtures/ClusterFixtures";
98
import {ClusterInfo} from "../apis/clusters";
109
import {TokenFixture} from "../test/fixtures/TokenFixtures";
1110
import {RetryConfigs} from "../retries/retries";
1211

13-
chai.use(chaiAsPromised);
14-
1512
describe(__filename, function () {
1613
this.timeout(new Time(10, TimeUnits.minutes).toMillSeconds().value);
1714

packages/databricks-vscode/src/configuration/ConnectionCommands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class ConnectionCommands implements Disposable {
111111
{
112112
label: "Create New Cluster",
113113
detail: `Open Databricks in the browser and create a new cluster`,
114-
alwaysShow: true,
114+
alwaysShow: false,
115115
},
116116
{
117117
label: "",
@@ -196,7 +196,7 @@ export class ConnectionCommands implements Disposable {
196196
{
197197
label: "Create New Repo",
198198
detail: `Open Databricks in the browser and create a new repo under /Repo/${me}`,
199-
alwaysShow: true,
199+
alwaysShow: false,
200200
},
201201
{
202202
label: "",

packages/databricks-vscode/src/configuration/ConnectionManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export class ConnectionManager {
318318
e
319319
);
320320
window.showErrorMessage(
321-
`Error in attaching cluster destination ${
321+
`Error in attaching cluster ${
322322
typeof cluster === "string" ? cluster : cluster.id
323323
}`
324324
);

0 commit comments

Comments
 (0)