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

Fix CodeQL fail tests #1034

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-pipelines-task-lib",
"version": "4.10.1",
"version": "4.11.0",
"description": "Azure Pipelines Task SDK",
"main": "./task.js",
"typings": "./task.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion node/test/toolrunnertests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ describe('Toolrunner Tests', function () {
});
})
it('Exec pipe output to another tool, succeeds if both tools succeed', function (done) {
this.timeout(30000);
this.timeout(120000);

var _testExecOptions = <trm.IExecOptions>{
cwd: __dirname,
Expand Down
123 changes: 77 additions & 46 deletions node/toolrunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,45 @@ export class ToolRunner extends events.EventEmitter {
this._debug(message);
});

let cp = child.spawn(this._getSpawnFileName(options), this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(options));
var stdbuffer: string = '';
var errbuffer: string = '';
const emitDoneEvent = function (resolve, reject) {
state.on('done', (error: Error, exitCode: number) => {
if (stdbuffer.length > 0) {
this.emit('stdline', stdbuffer);
}

if (errbuffer.length > 0) {
this.emit('errline', errbuffer);
}

if (cp) {
cp.removeAllListeners();
}

if (error) {
reject(error);
}
else {
resolve(exitCode);
}
});
}

// Edge case when the node itself cant's spawn and emit event
let cp;
try {
cp = child.spawn(this._getSpawnFileName(options), this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(options));
} catch (error) {
return new Promise((resolve, reject) => {
emitDoneEvent(resolve, reject);
state.processError = error.message;
state.processExited = true;
state.processClosed = true;
state.CheckComplete();
});
}

this.childProcess = cp;
// it is possible for the child process to end its last line without a new line.
// because stdout is buffered, this causes the last line to not get sent to the parent
Expand All @@ -1109,7 +1147,6 @@ export class ToolRunner extends events.EventEmitter {
}
});

var stdbuffer: string = '';
cp.stdout?.on('data', (data: Buffer) => {
this.emit('stdout', data);

Expand All @@ -1122,8 +1159,6 @@ export class ToolRunner extends events.EventEmitter {
});
});


var errbuffer: string = '';
cp.stderr?.on('data', (data: Buffer) => {
state.processStderr = true;
this.emit('stderr', data);
Expand Down Expand Up @@ -1160,26 +1195,7 @@ export class ToolRunner extends events.EventEmitter {
state.CheckComplete();
});

return new Promise((resolve, reject) => {
state.on('done', (error: Error, exitCode: number) => {
if (stdbuffer.length > 0) {
this.emit('stdline', stdbuffer);
}

if (errbuffer.length > 0) {
this.emit('errline', errbuffer);
}

cp.removeAllListeners();

if (error) {
reject(error);
}
else {
resolve(exitCode);
}
});
});
return new Promise(emitDoneEvent);
}

/**
Expand Down Expand Up @@ -1215,7 +1231,43 @@ export class ToolRunner extends events.EventEmitter {
this._debug(message);
});

let cp = child.spawn(this._getSpawnFileName(options), this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(options));
var stdbuffer: string = '';
var errbuffer: string = '';
state.on('done', (error: Error, exitCode: number) => {
if (stdbuffer.length > 0) {
this.emit('stdline', stdbuffer);
}

if (errbuffer.length > 0) {
this.emit('errline', errbuffer);
}

if (cp) {
cp.removeAllListeners();
}

if (error) {
defer.reject(error);
}
else {
defer.resolve(exitCode);
}
});


// Edge case when the node itself cant's spawn and emit event
let cp;
try {
cp = child.spawn(this._getSpawnFileName(options), this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(options));
} catch (error) {
state.processError = error.message;
state.processExited = true;
state.processClosed = true;
state.CheckComplete();

return defer.promise;
}

this.childProcess = cp;
// it is possible for the child process to end its last line without a new line.
// because stdout is buffered, this causes the last line to not get sent to the parent
Expand All @@ -1226,7 +1278,6 @@ export class ToolRunner extends events.EventEmitter {
}
});

var stdbuffer: string = '';
cp.stdout?.on('data', (data: Buffer) => {
this.emit('stdout', data);

Expand All @@ -1240,7 +1291,6 @@ export class ToolRunner extends events.EventEmitter {
});


var errbuffer: string = '';
cp.stderr?.on('data', (data: Buffer) => {
state.processStderr = true;
this.emit('stderr', data);
Expand Down Expand Up @@ -1277,25 +1327,6 @@ export class ToolRunner extends events.EventEmitter {
state.CheckComplete();
});

state.on('done', (error: Error, exitCode: number) => {
if (stdbuffer.length > 0) {
this.emit('stdline', stdbuffer);
}

if (errbuffer.length > 0) {
this.emit('errline', errbuffer);
}

cp.removeAllListeners();

if (error) {
defer.reject(error);
}
else {
defer.resolve(exitCode);
}
});

return defer.promise;
}

Expand Down