Skip to content

Commit 0a63b03

Browse files
authored
* replace `wait` util with `timeout` usage * remove `waitRandom` * use `mock` over `mockObject` duplicate
1 parent ab6d98e commit 0a63b03

File tree

10 files changed

+51
-197
lines changed

10 files changed

+51
-197
lines changed

src/vs/base/test/common/logTime.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import assert from 'assert';
77
import * as sinon from 'sinon';
8-
import { waitRandom } from './testUtils.js';
8+
import { timeout } from '../../common/async.js';
99
import { randomInt } from '../../common/numbers.js';
1010
import { ensureNoDisposablesAreLeakedInTestSuite } from './utils.js';
1111
import { logExecutionTime, logTime } from '../../common/decorators/logTime.js';
@@ -46,7 +46,7 @@ suite('logTime', () => {
4646

4747
@logTime()
4848
public async myAsyncMethod(): Promise<number> {
49-
await waitRandom(10);
49+
await timeout(10);
5050

5151
return this.returnValue;
5252
}
@@ -146,7 +146,7 @@ suite('logTime', () => {
146146

147147
@logTime()
148148
public async myAsyncMethod(): Promise<number> {
149-
await waitRandom(10);
149+
await timeout(10);
150150

151151
return this.returnValue;
152152
}
@@ -196,7 +196,7 @@ suite('logTime', () => {
196196
const resultPromise = logExecutionTime(
197197
'my-async-function',
198198
async () => {
199-
await waitRandom(10);
199+
await timeout(10);
200200

201201
return expectedReturnValue;
202202
},

src/vs/base/test/common/mockObject.test.ts

Lines changed: 0 additions & 101 deletions
This file was deleted.

src/vs/base/test/common/objectCache.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import assert from 'assert';
77
import { spy } from 'sinon';
88
import { ObjectCache } from '../../common/objectCache.js';
9-
import { wait } from '../../../base/test/common/testUtils.js';
9+
import { timeout } from '../../../base/common/async.js';
1010
import { ObservableDisposable } from '../../common/observableDisposable.js';
1111
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../base/test/common/utils.js';
1212

@@ -126,7 +126,7 @@ suite('ObjectCache', function () {
126126
obj3.dispose();
127127
// the object is removed from the cache asynchronously
128128
// so add a small delay to ensure the object is removed
129-
await wait(5);
129+
await timeout(5);
130130

131131
const obj5 = cache.get(key1);
132132
assert(

src/vs/base/test/common/observableDisposable.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55
import assert from 'assert';
66
import { spy } from 'sinon';
7-
import { wait, waitRandom } from './testUtils.js';
7+
import { timeout } from '../../common/async.js';
88
import { randomInt } from '../../common/numbers.js';
99
import { Disposable, IDisposable } from '../../common/lifecycle.js';
1010
import { ensureNoDisposablesAreLeakedInTestSuite } from './utils.js';
@@ -62,7 +62,7 @@ suite('ObservableDisposable', () => {
6262
'`onDispose` callback must not be called yet.',
6363
);
6464

65-
await waitRandom(10);
65+
await timeout(10);
6666

6767
assert(
6868
onDisposeSpy.notCalled,
@@ -71,7 +71,7 @@ suite('ObservableDisposable', () => {
7171

7272
// dispose object and wait for the event to be fired/received
7373
object.dispose();
74-
await wait(1);
74+
await timeout(1);
7575

7676
/**
7777
* Validate that the callback was called.
@@ -93,7 +93,7 @@ suite('ObservableDisposable', () => {
9393

9494
object.dispose();
9595
object.dispose();
96-
await waitRandom(10, 5);
96+
await timeout(10);
9797
object.dispose();
9898

9999
assert(
@@ -115,23 +115,23 @@ suite('ObservableDisposable', () => {
115115

116116
// dispose object and wait for the event to be fired/received
117117
object.dispose();
118-
await wait(10);
118+
await timeout(10);
119119

120120
const onDisposeSpy = spy();
121121
disposables.add(object.onDispose(onDisposeSpy));
122122

123-
await wait(10);
123+
await timeout(10);
124124

125125
assert(
126126
onDisposeSpy.calledOnce,
127127
'`onDispose` callback must be called immediately.',
128128
);
129129

130-
await waitRandom(10, 5);
130+
await timeout(10);
131131

132132
disposables.add(object.onDispose(onDisposeSpy));
133133

134-
await wait(10);
134+
await timeout(10);
135135

136136
assert(
137137
onDisposeSpy.calledTwice,
@@ -140,7 +140,7 @@ suite('ObservableDisposable', () => {
140140

141141
// dispose object and wait for the event to be fired/received
142142
object.dispose();
143-
await wait(10);
143+
await timeout(10);
144144

145145
assert(
146146
onDisposeSpy.calledTwice,
@@ -301,21 +301,21 @@ suite('ObservableDisposable', () => {
301301
object.assertNotDisposed('Object must not be disposed.');
302302
});
303303

304-
await waitRandom(10);
304+
await timeout(10);
305305

306306
assert.doesNotThrow(() => {
307307
object.assertNotDisposed('Object must not be disposed.');
308308
});
309309

310310
// dispose object and wait for the event to be fired/received
311311
object.dispose();
312-
await wait(1);
312+
await timeout(1);
313313

314314
assert.throws(() => {
315315
object.assertNotDisposed('Object must not be disposed.');
316316
});
317317

318-
await waitRandom(10);
318+
await timeout(10);
319319

320320
assert.throws(() => {
321321
object.assertNotDisposed('Object must not be disposed.');
@@ -335,7 +335,7 @@ suite('ObservableDisposable', () => {
335335
);
336336
});
337337

338-
await waitRandom(10);
338+
await timeout(10);
339339

340340
assert.doesNotThrow(() => {
341341
assertNotDisposed(
@@ -346,7 +346,7 @@ suite('ObservableDisposable', () => {
346346

347347
// dispose object and wait for the event to be fired/received
348348
object.dispose();
349-
await wait(1);
349+
await timeout(1);
350350

351351
assert.throws(() => {
352352
assertNotDisposed(
@@ -355,7 +355,7 @@ suite('ObservableDisposable', () => {
355355
);
356356
});
357357

358-
await waitRandom(10);
358+
await timeout(10);
359359

360360
assert.throws(() => {
361361
assertNotDisposed(

src/vs/base/test/common/testUtils.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { assert } from '../../common/assert.js';
7-
import { isOneOf } from '../../common/types.js';
8-
import { randomInt } from '../../common/numbers.js';
96

107
export function flakySuite(title: string, fn: () => void) /* Suite */ {
118
return suite(title, function () {
@@ -22,22 +19,6 @@ export function flakySuite(title: string, fn: () => void) /* Suite */ {
2219
});
2320
}
2421

25-
/**
26-
* @deprecated use `async#timeout` instead
27-
*/
28-
export const wait = (ms: number): Promise<void> => {
29-
return new Promise(resolve => setTimeout(resolve, ms));
30-
};
31-
32-
/**
33-
* Helper function that allows to await for a random amount of time.
34-
* @param maxMs The `maximum` amount of time to wait, in milliseconds.
35-
* @param minMs [`optional`] The `minimum` amount of time to wait, in milliseconds.
36-
*/
37-
export const waitRandom = (maxMs: number, minMs: number = 0): Promise<void> => {
38-
return wait(randomInt(maxMs, minMs));
39-
};
40-
4122
/**
4223
* (pseudo)Random boolean generator.
4324
*
@@ -51,32 +32,3 @@ export const waitRandom = (maxMs: number, minMs: number = 0): Promise<void> => {
5132
export const randomBoolean = (): boolean => {
5233
return Math.random() > 0.5;
5334
};
54-
55-
/**
56-
* @deprecated use `mock.ts#mock` instead
57-
*/
58-
export function mockObject<TObject extends Object>(
59-
overrides: Partial<TObject>,
60-
): TObject {
61-
// ensure that the overrides object cannot be modified afterward
62-
overrides = Object.freeze(overrides);
63-
64-
const keys = Object.keys(overrides) as (keyof (typeof overrides))[];
65-
const service = new Proxy(
66-
{},
67-
{
68-
get: (_target, key: string | number | Symbol) => {
69-
// sanity check for the provided `key`
70-
assert(
71-
isOneOf(key, keys),
72-
`The '${key}' is not mocked.`,
73-
);
74-
75-
return overrides[key];
76-
},
77-
});
78-
79-
// note! it's ok to `as TObject` here, because of
80-
// the runtime checks in the `Proxy` getter
81-
return service as (typeof overrides) as TObject;
82-
}

0 commit comments

Comments
 (0)