forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcacheUtils.unit.test.ts
More file actions
56 lines (44 loc) · 1.72 KB
/
cacheUtils.unit.test.ts
File metadata and controls
56 lines (44 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { assert } from 'chai';
import * as sinon from 'sinon';
import { InMemoryCache } from '../../../client/common/utils/cacheUtils';
suite('Common Utils - CacheUtils', () => {
suite('InMemory Cache', () => {
let clock: sinon.SinonFakeTimers;
setup(() => {
clock = sinon.useFakeTimers();
});
teardown(() => clock.restore());
test('Cached item should exist', () => {
const cache = new InMemoryCache(5_000);
cache.data = 'Hello World';
assert.equal(cache.data, 'Hello World');
assert.isOk(cache.hasData);
});
test('Cached item can be updated and should exist', () => {
const cache = new InMemoryCache(5_000);
cache.data = 'Hello World';
assert.equal(cache.data, 'Hello World');
assert.isOk(cache.hasData);
cache.data = 'Bye';
assert.equal(cache.data, 'Bye');
assert.isOk(cache.hasData);
});
test('Cached item should not exist after time expires', () => {
const cache = new InMemoryCache(5_000);
cache.data = 'Hello World';
assert.equal(cache.data, 'Hello World');
assert.isTrue(cache.hasData);
// Should not expire after 4.999s.
clock.tick(4_999);
assert.equal(cache.data, 'Hello World');
assert.isTrue(cache.hasData);
// Should expire after 5s (previous 4999ms + 1ms).
clock.tick(1);
assert.equal(cache.data, undefined);
assert.isFalse(cache.hasData);
});
});
});