提交 68e01820 编写于 作者: M Matt Bierner

Add test for not caching cancelled response

上级 863aee78
......@@ -8,7 +8,7 @@ import 'mocha';
import * as vscode from 'vscode';
import * as Proto from '../protocol';
import { CachedResponse } from '../tsServer/cachedResponse';
import { ServerResponse } from '../typescriptService';
import { ServerResponse, CancelledResponse } from '../typescriptService';
suite('CachedResponse', () => {
test('should cache simple response for same document', async () => {
......@@ -16,7 +16,7 @@ suite('CachedResponse', () => {
const response = new CachedResponse();
let seq = 0;
const makeRequest = async () => createSuccessResponse(`test-${seq++}`);
const makeRequest = async () => createResponse(`test-${seq++}`);
assertResult(await response.execute(doc, makeRequest), 'test-0');
assertResult(await response.execute(doc, makeRequest), 'test-0');
......@@ -28,7 +28,7 @@ suite('CachedResponse', () => {
const response = new CachedResponse();
let seq = 0;
const makeRequest = async () => createSuccessResponse(`test-${seq++}`);
const makeRequest = async () => createResponse(`test-${seq++}`);
assertResult(await response.execute(doc1, makeRequest), 'test-0');
assertResult(await response.execute(doc1, makeRequest), 'test-0');
......@@ -37,6 +37,20 @@ suite('CachedResponse', () => {
assertResult(await response.execute(doc1, makeRequest), 'test-2');
assertResult(await response.execute(doc1, makeRequest), 'test-2');
});
test('should not cache canceled response', async () => {
const doc = await vscode.workspace.openTextDocument({ language: 'javascript', content: '' });
const response = new CachedResponse();
let seq = 0;
const makeRequest = async () => createResponse(`test-${seq++}`);
const result1 = await response.execute(doc, async () => new CancelledResponse('cancleed'));
assert.strictEqual(result1.type, 'cancelled');
assertResult(await response.execute(doc, makeRequest), 'test-0');
assertResult(await response.execute(doc, makeRequest), 'test-0');
});
});
function assertResult(result: ServerResponse<Proto.Response>, command: string) {
......@@ -47,7 +61,7 @@ function assertResult(result: ServerResponse<Proto.Response>, command: string) {
}
}
function createSuccessResponse(command: string): Proto.Response {
function createResponse(command: string): Proto.Response {
return {
type: 'response',
body: {},
......@@ -57,3 +71,4 @@ function createSuccessResponse(command: string): Proto.Response {
seq: 1
};
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册