Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add std out to subprocess to stop overflow #21758

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/client/testing/testController/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,16 @@ export class PythonTestServer implements ITestServer, Disposable {
runInstance?.token.onCancellationRequested(() => {
result?.proc?.kill();
});
result?.proc?.on('close', () => {

// Take all output from the subprocess and add it to the test output channel. This will be the pytest output.
// Displays output to user and ensure the subprocess doesn't run into buffer overflow.
result?.proc?.stdout?.on('data', (data) => {
spawnOptions?.outputChannel?.append(data);
});
result?.proc?.stderr?.on('data', (data) => {
spawnOptions?.outputChannel?.append(data);
});
result?.proc?.on('exit', () => {
traceLog('Exec server closed.', uuid);
deferred.resolve({ stdout: '', stderr: '' });
callback?.();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,15 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
const execArgs = ['-m', 'pytest', '-p', 'vscode_pytest', '--collect-only'].concat(pytestArgs);
const result = execService?.execObservable(execArgs, spawnOptions);

result?.proc?.on('close', () => {
// Take all output from the subprocess and add it to the test output channel. This will be the pytest output.
// Displays output to user and ensure the subprocess doesn't run into buffer overflow.
result?.proc?.stdout?.on('data', (data) => {
spawnOptions.outputChannel?.append(data);
});
result?.proc?.stderr?.on('data', (data) => {
spawnOptions.outputChannel?.append(data);
});
result?.proc?.on('exit', () => {
deferredExec.resolve({ stdout: '', stderr: '' });
this.testServer.deleteUUID(uuid);
deferred.resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
result?.proc?.kill();
});

// Take all output from the subprocess and add it to the test output channel. This will be the pytest output.
// Displays output to user and ensure the subprocess doesn't run into buffer overflow.
result?.proc?.stdout?.on('data', (data) => {
this.outputChannel?.append(data);
});
result?.proc?.stderr?.on('data', (data) => {
this.outputChannel?.append(data);
});

result?.proc?.on('close', () => {
deferredExec.resolve({ stdout: '', stderr: '' });
this.testServer.deleteUUID(uuid);
Expand Down
11 changes: 11 additions & 0 deletions src/test/mocks/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { Readable } from 'stream';

export class MyReadableStream extends Readable {
eleanorjboyd marked this conversation as resolved.
Show resolved Hide resolved
_read(_size: unknown): void | null {
// custom reading logic here
this.push(null); // end the stream
}
}
7 changes: 4 additions & 3 deletions src/test/mocks/mockChildProcess.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Serializable, SendHandle, MessageOptions } from 'child_process';
import { Writable, Readable, Pipe } from 'stream';
import { EventEmitter } from 'node:events';
import { Writable, Readable, Pipe } from 'stream';
import { MyReadableStream } from './helper';

export class MockChildProcess extends EventEmitter {
constructor(spawnfile: string, spawnargs: string[]) {
super();
this.spawnfile = spawnfile;
this.spawnargs = spawnargs;
this.stdin = new Writable();
this.stdout = new Readable();
this.stderr = null;
this.stdout = new MyReadableStream();
this.stderr = new MyReadableStream();
this.channel = null;
this.stdio = [this.stdin, this.stdout, this.stdout, this.stderr, null];
this.killed = false;
Expand Down