fix tests

This commit is contained in:
Benjamin Pasero 2021-04-06 10:14:45 +02:00
parent 8684456b1e
commit 6f8b983dfd
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65

View file

@ -23,6 +23,7 @@ import { mock } from 'vs/base/test/common/mock';
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
import { TextSearchManager } from 'vs/workbench/services/search/common/textSearchManager';
import { NativeTextSearchManager } from 'vs/workbench/services/search/node/textSearchManager';
import { timeout } from 'vs/base/common/async';
let rpcProtocol: TestRPCProtocol;
let extHostSearch: NativeExtHostSearch;
@ -83,7 +84,7 @@ suite('ExtHostSearch', () => {
const cancellation = new CancellationTokenSource();
const p = extHostSearch.$provideFileSearchResults(mockMainThreadSearch.lastHandle, 0, query, cancellation.token);
if (cancel) {
await new Promise(resolve => process.nextTick(resolve));
await timeout(0);
cancellation.cancel();
}
@ -102,15 +103,11 @@ suite('ExtHostSearch', () => {
};
}
async function runTextSearch(query: ITextQuery, cancel = false): Promise<{ results: IFileMatch[], stats: ISearchCompleteStats }> {
async function runTextSearch(query: ITextQuery): Promise<{ results: IFileMatch[], stats: ISearchCompleteStats }> {
let stats: ISearchCompleteStats;
try {
const cancellation = new CancellationTokenSource();
const p = extHostSearch.$provideTextSearchResults(mockMainThreadSearch.lastHandle, 0, query, cancellation.token);
if (cancel) {
await new Promise(resolve => process.nextTick(resolve));
cancellation.cancel();
}
stats = await p;
} catch (err) {
@ -223,12 +220,19 @@ suite('ExtHostSearch', () => {
let cancelRequested = false;
await registerTestFileSearchProvider({
provideFileSearchResults(query: vscode.FileSearchQuery, options: vscode.FileSearchOptions, token: vscode.CancellationToken): Promise<URI[]> {
return new Promise((resolve, reject) => {
token.onCancellationRequested(() => {
function onCancel() {
cancelRequested = true;
resolve([joinPath(options.folder, 'file1.ts')]); // or reject or nothing?
});
}
if (token.isCancellationRequested) {
onCancel();
} else {
token.onCancellationRequested(() => onCancel());
}
});
}
});