Skip to content

Commit 5bafaa5

Browse files
tasks: remove RpcProtocol from task test (eclipse-theia#12054)
One of the task test cases relies on the protocol used by terminals to communicate data, but the protocol has been updated in eclipse-theia#11972.
1 parent 92e9581 commit 5bafaa5

File tree

1 file changed

+18
-36
lines changed

1 file changed

+18
-36
lines changed

packages/task/src/node/task-server.slow-spec.ts

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { expectThrowsAsync } from '@theia/core/lib/common/test/expect';
2929
import { TestWebSocketChannelSetup } from '@theia/core/lib/node/messaging/test/test-web-socket-channel';
3030
import { expect } from 'chai';
3131
import URI from '@theia/core/lib/common/uri';
32-
import { RpcProtocol } from '@theia/core';
32+
import { StringBufferingStream } from '@theia/terminal/lib/node/buffering-stream';
3333

3434
// test scripts that we bundle with tasks
3535
const commandShortRunning = './task';
@@ -89,12 +89,6 @@ describe('Task server / back-end', function (): void {
8989
it('task running in terminal - expected data is received from the terminal ws server', async function (): Promise<void> {
9090
const someString = 'someSingleWordString';
9191

92-
// This test is flaky on Windows and fails intermittently. Disable it for now
93-
if (isWindows) {
94-
this.skip();
95-
return;
96-
}
97-
9892
// create task using terminal process
9993
const command = isWindows ? commandShortRunningWindows : (isOSX ? commandShortRunningOsx : commandShortRunning);
10094
const taskInfo: TaskInfo = await taskServer.run(createProcessTaskConfig('shell', `${command} ${someString}`), wsRoot);
@@ -103,40 +97,28 @@ describe('Task server / back-end', function (): void {
10397
const messagesToWaitFor = 10;
10498
const messages: string[] = [];
10599

100+
// check output of task on terminal is what we expect
101+
const expected = `${isOSX ? 'tasking osx' : 'tasking'}... ${someString}`;
102+
106103
// hook-up to terminal's ws and confirm that it outputs expected tasks' output
107104
await new Promise<void>((resolve, reject) => {
108105
const setup = new TestWebSocketChannelSetup({ server, path: `${terminalsPath}/${terminalId}` });
106+
const stringBuffer = new StringBufferingStream();
109107
setup.multiplexer.onDidOpenChannel(event => {
110-
const channel = event.channel;
111-
const connection = new RpcProtocol(channel, async (method, args) => {
112-
const error = new Error(`Received unexpected request: ${method} with args: ${args} `);
113-
reject(error);
114-
throw error;
115-
});
116-
channel.onError(reject);
117-
channel.onClose(() => reject(new Error('Channel has been closed')));
118-
connection.onNotification(not => {
119-
// check output of task on terminal is what we expect
120-
const expected = `${isOSX ? 'tasking osx' : 'tasking'}... ${someString}`;
121-
// Instead of waiting for one message from the terminal, we wait for several ones as the very first message can be something unexpected.
122-
// For instance: `nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"/usr/local\"\r\n`
123-
const currentMessage = not.args[0];
124-
messages.unshift(currentMessage);
125-
if (currentMessage.indexOf(expected) !== -1) {
126-
resolve();
127-
channel.close();
128-
return;
129-
}
130-
if (messages.length >= messagesToWaitFor) {
131-
reject(new Error(`expected sub-string not found in terminal output. Expected: "${expected}" vs Actual messages: ${JSON.stringify(messages)}`));
132-
channel.close();
133-
}
134-
});
135-
channel.onMessage(reader => {
136-
137-
});
108+
event.channel.onMessage(e => stringBuffer.push(e().readString()));
109+
event.channel.onError(reject);
110+
event.channel.onClose(() => reject(new Error('Channel has been closed')));
111+
});
112+
stringBuffer.onData(currentMessage => {
113+
// Instead of waiting for one message from the terminal, we wait for several ones as the very first message can be something unexpected.
114+
// For instance: `nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"/usr/local\"\r\n`
115+
messages.unshift(currentMessage);
116+
if (currentMessage.includes(expected)) {
117+
resolve();
118+
} else if (messages.length >= messagesToWaitFor) {
119+
reject(new Error(`expected sub-string not found in terminal output. Expected: "${expected}" vs Actual messages: ${JSON.stringify(messages)}`));
120+
}
138121
});
139-
140122
});
141123
});
142124

0 commit comments

Comments
 (0)