mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 01:58:53 +01:00
Fix MdDocumentInfoCache computing values twice (#152799)
* Fix MdDocumentInfoCache computing values twice Fixes a race where values could be computed twice before being cached * Remove only
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import 'mocha';
|
||||
import { InMemoryDocument } from '../util/inMemoryDocument';
|
||||
import { MdDocumentInfoCache } from '../util/workspaceCache';
|
||||
import { InMemoryWorkspaceMarkdownDocuments } from './inMemoryWorkspace';
|
||||
import { workspacePath } from './util';
|
||||
|
||||
suite('DocumentInfoCache', () => {
|
||||
test('Repeated calls should only compute value once', async () => {
|
||||
const doc = workspacePath('doc.md');
|
||||
const workspace = new InMemoryWorkspaceMarkdownDocuments([
|
||||
new InMemoryDocument(doc, '')
|
||||
]);
|
||||
|
||||
let i = 0;
|
||||
const cache = new MdDocumentInfoCache<number>(workspace, async () => {
|
||||
return ++i;
|
||||
});
|
||||
|
||||
const a = cache.get(doc);
|
||||
const b = cache.get(doc);
|
||||
|
||||
assert.strictEqual(await a, 1);
|
||||
assert.strictEqual(i, 1);
|
||||
assert.strictEqual(await b, 1);
|
||||
assert.strictEqual(i, 1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user