Skip to content

Commit 4e1e645

Browse files
committed
test(transport): high-traffic RPC
Problem: In vscode-neovim/vscode-neovim#2184 (comment) it was reported that "Github Copilot Chat opens MANY buffers while writing code, and that somehow breaks the vscode-neovim extension". Solution: - Add test coverage for high amounts of RPC traffic. - TODO: this doesn't cover complex scenarios such as a looping `OptionSet` handler.
1 parent ba4c247 commit 4e1e645

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

packages/neovim/src/api/Base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export class BaseApi extends EventEmitter {
118118
});
119119
}
120120

121+
/** Sends a request to Nvim (the peer). */
121122
request(name: string, args: any[] = []): Promise<any> {
122123
return this.asyncRequest(name, args);
123124
}

packages/neovim/src/api/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export class NeovimClient extends Neovim {
6363
return this.attachedBuffers.has(key);
6464
}
6565

66+
/** Handles incoming request (from the peer). */
6667
handleRequest(
6768
method: string,
6869
args: VimValue[],
@@ -85,6 +86,7 @@ export class NeovimClient extends Neovim {
8586
}
8687
}
8788

89+
/** Publishes to (local) subscribers of this `EventEmitter`. */
8890
emitNotification(method: string, args: any[]) {
8991
if (method.endsWith('_event')) {
9092
if (!method.startsWith('nvim_buf_')) {
@@ -114,6 +116,7 @@ export class NeovimClient extends Neovim {
114116
}
115117
}
116118

119+
/** Handles incoming notification (from the peer). */
117120
handleNotification(method: string, args: VimValue[], ...restArgs: any[]) {
118121
this.logger.info('handleNotification: %s', method);
119122
// If neovim API is not generated yet then queue up requests

packages/neovim/src/attach/attach.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ import { NeovimClient } from '../api/client';
77
describe('Nvim API', () => {
88
let proc: ReturnType<typeof testUtil.startNvim>[0];
99
let nvim: ReturnType<typeof testUtil.startNvim>[1];
10+
/** Incoming requests (from Nvim). */
1011
let requests: { method: string; args: number[] }[];
12+
/** Incoming notifications (from Nvim). */
1113
let notifications: { method: string; args: number[] }[];
1214

1315
beforeAll(async () => {
1416
[proc, nvim] = testUtil.startNvim();
1517

18+
// Incoming requests (from Nvim).
1619
nvim.on('request', (method, args, resp) => {
1720
requests.push({ method, args });
1821
resp.send(`received ${method}(${args})`);
1922
});
23+
24+
// Incoming notifications (from Nvim).
2025
nvim.on('notification', (method, args) => {
2126
notifications.push({ method, args });
2227
});
@@ -95,6 +100,29 @@ describe('Nvim API', () => {
95100
testUtil.stopNvim(nvim2);
96101
});
97102

103+
it('noisy RPC traffic', async () => {
104+
let requestCount = 0;
105+
const oldRequest = nvim.request;
106+
nvim.request = function (
107+
this: any,
108+
name: string,
109+
args: any[] = []
110+
): Promise<any> {
111+
requestCount = requestCount + 1;
112+
return oldRequest.call(this, name, args);
113+
};
114+
115+
for (let i = 0; i < 99; i = i + 1) {
116+
nvim.command('noswapfile edit test-node-client.lua');
117+
nvim.command('bwipeout!');
118+
}
119+
120+
expect(requestCount).toEqual(99 * 2);
121+
122+
// Still alive?
123+
expect(await nvim.eval('1+1')).toEqual(2);
124+
});
125+
98126
it('can send requests and receive response', async () => {
99127
const result = await nvim.eval('{"k1": "v1", "k2": 2}');
100128
expect(result).toEqual({ k1: 'v1', k2: 2 });
@@ -143,7 +171,7 @@ describe('Nvim API', () => {
143171
end: -1,
144172
strictIndexing: true,
145173
});
146-
expect(lines).toEqual([]);
174+
expect(lines).toEqual(['']);
147175

148176
buf.setLines(['line1', 'line2'], { start: 0, end: 1 });
149177
const newLines = await buf.getLines({

0 commit comments

Comments
 (0)